当我想使用扫描仪读取用户的名称,然后在字符串中分配名称的值,然后调用方法 getName 并给它一个名称参数以打印出我的名字是....,我的代码只是崩溃并且不起作用我试图找出问题但我无法
public void getName(String name)
{
String s = "your name is: "+name ;
}
public void userInput()
{
print();
Scanner s = new Scanner(System.in);
String read = s.nextLine();
String op = read;
while(!read.equals("Exit"))
{
switch (op){
case "a" :
System.out.println("type your name:");
read = s.nextLine();
getName(read);
print();
read = s.nextLine();
op = read;
break;
case"b" :
System.out.println("by");
print();
read = s.nextLine();
op = read;
break;
}
}
}
public void print()
{
System.out.println("press a");
System.out.println("press b");
}