首先我宣布了n。我从用户那里接受了n。然后打印它的价值。错误来了。
public class Class {
public static void main(String[] args) {
String n;
double s;
Scanner scan=new Scanner(System.in);
System.out.println("Enter the Name:");
if (scan.hasNextLine()) {
n=scan.nextLine();
}
System.out.println("Enter the salary:");
if (scan.hasNextDouble()) {
s=scan.nextDouble();
}
System.out.println("Name is: "+n);
//error: The local variable n may not have been initialised.
System.out.println("Salary is: "+s);
//error: The local variable s may not have been initialised.
scan.close();
}
}
答案 0 :(得分:0)
初始化变量n,s: 字符串n =“”; double s = 0;