假设您有一个txt文件,同时查看前10行和后10行文件的命令是什么?
即如果文件长度为200行,则一次查看1-10行和190-200行.
我遇到了一个扩展Stash的actor的问题,并且在一个简单的ActorSystem中使用actorOf实例化它时效果非常好.现在我真的想在我的程序中使用它们之前为我的存储演员编写一些测试.但是我无法找到在我的测试套件中使用TestActorRef和这个actor的方法.
有效的代码如下所示:
import akka.actor.{Stash, Actor, ActorSystem, Props}
import com.typesafe.config.ConfigFactory
object StashTest {
val config = ConfigFactory.parseString(
"""
|akka.actor.default-mailbox {
| mailbox-type = "akka.dispatch.UnboundedDequeBasedMailbox"
|}
""".stripMargin)
}
class StashTestActor extends Stash {
def receive: Actor.Receive = {
case "unstash" =>
unstashAll()
context become print
case msg => stash()
}
def print: Actor.Receive = {
case msg => println(s"Unstashed message: $msg")
}
}
val system = ActorSystem("stashSystem", StashTest.config)
val ref = system.actorOf(Props[StashTestActor])
ref ! "stash me"
ref ! "blah"
ref ! "unstash" …Run Code Online (Sandbox Code Playgroud) 我在Programming in Scala书中阅读有关折叠技术的信息并且遇到了这个片段:
def reverseLeft[T](xs:List[T]) = (List[T]() /: xs) {
(y,ys) => ys :: y
}
Run Code Online (Sandbox Code Playgroud)
如您所见,它是使用foldLeft或/:运算符完成的.好奇如果我使用它会是什么样子:\,我想出了这个:
def reverseRight[T](xs:List[T]) = (xs :\ List[T]()) {
(y,ys) => ys ::: List(y)
}
Run Code Online (Sandbox Code Playgroud)
根据我的理解,它:::似乎没有那么快,::并且具有线性成本,具体取决于操作数列表的大小.不可否认,我没有CS的背景,也没有先前的FP经验.所以我的问题是:
:::?我正在尝试为酒店创建一个程序,用户输入一个字符(S,D或L),并且该字符应该与下一行的代码相对应.我需要帮助转换用户输入(无论他们输入什么方式)转换为大写,然后我可以使用if语句来做我需要做的事情.到目前为止,我的代码如下:
public static void Main()
{
int numdays;
double total = 0.0;
char roomtype, Continue;
Console.WriteLine("Welcome to checkout. We hope you enjoyed your stay!");
do
{
Console.Write("Please enter the number of days you stayed: ");
numdays = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("S = Single, D = Double, L = Luxery");
Console.Write("Please enter the type of room you stayed in: ");
roomtype = Convert.ToChar(Console.ReadLine());
**^Right Her is Where I Want To Convert To Uppercase^**
total = RoomCharge(numdays,roomtype);
Console.WriteLine("Thank you for staying at …Run Code Online (Sandbox Code Playgroud) [[1,3,4],[1,5,6,7],[2,8,0]]假设我有一个像or这样的列表列表["QQQ", "RRRR", "TTTTT"],是否有一个函数可以按内部列表中的元素数量对它们进行排序,即在列表中,Int4 个元素列表位于前面,而在Strings 列表中,Ts 位于前面到前面然后是Rs?
public static double changeToSpeed(String time, int distance)
{
if(time.indexOf(":") == 1){
int minutes = time.charAt(0);
String sec = time.substring(3, 7);
double seconds = Double.parseDouble(sec);
double totalTime = 60 * minutes + seconds;
double endSpeed = distance / totalTime;
return endSpeed;
}
else if(time.indexOf(":") == 2){
String min = time.substring(0, 2);
String sec = time.substring(3, 7);
double minutes = Double.parseDouble(min);
double seconds = Double.parseDouble(sec);
double totalTime = 60 * minutes + seconds;
double endSpeed = distance / totalTime;
return endSpeed;
} …Run Code Online (Sandbox Code Playgroud) if even 2 then 10 else 11 -- works fine
if even 2 then let t = 10 else let s = 11 -- _:27: parse error on input 'else'
if even 2 then 10 else let s = 11 -- _:34 parse error (possibly incorrect indentation or mismatched brackets)
Run Code Online (Sandbox Code Playgroud)
因为假设我想用 [[p]] 编写这样的代码:
[ t | let e = [],
let o = p!!14, r <- [13,12..1],
if even r
then
let o = zipWith (+) (p!!r) (zipWith max e …Run Code Online (Sandbox Code Playgroud) 这是代码本身
import java.util.ArrayList;
public class Student {
private String name;
private int age;
public Student (String n, int a) {
name = n;
age = a;
}
public String toString() {
return name + " is " + age + " years old";
}
ArrayList<Student> rayList = new ArrayList<Student>();
rayList.add(new Student("Sam", 17));
rayList.add(new Student("Sandra", 18));
rayList.add(new Student("Billy", 16));
rayList.add(new Student("Greg", 17));
rayList.add(new Student("Jill", 18));
public static void main(String[] args) {
System.out.println(rayList.get(0));
}
}
Run Code Online (Sandbox Code Playgroud)
main方法中缺少一些println命令.但是当我尝试将5个学生添加到我的ArrayList时,我收到错误"无法对非静态字段rayList进行静态引用"