试图找出我的String userString ="&#34 ;;不被承认。我的所有其他变量类型都显示为不同的颜色。
由于
import java.util.Scanner;
public class BasicInput {
public static void main (String [] args) {
Scanner scnr = new Scanner(System.in);
int userInt = 0;
double userDouble = 0.0;
char userChar = 'a';
String userString = "";
System.out.println("Enter integer: ");
userInt = scnr.nextInt();
System.out.println("Enter double: ");
userDouble = scnr.nextDouble();
System.out.println("Enter character: ");
userChar = scnr.next().charAt(0);
System.out.println("Enter string: ");
userString = scnr.nextLine();
System.out.println(userInt + " " + userDouble + " " + userChar + " " + userString);
return;
}
}
答案 0 :(得分:0)
运行代码这是输出:
Enter integer:
1
Enter double:
22
Enter character:
b
Enter string:
1 22.0 b //Skips the userString = scnr.nextLine(); and jumps to the last println
出于某种原因,当我运行程序时,使用不同的.nextLine... .nextInt .next
,它只使用.nextLine
跳过读取最后一行,然后使用方法检查String
是否为double
integer
或char
可以解决此问题