我几次遇到过这个错误,我尝试了很多东西来修复它,但我似乎无法找出出错的地方。这是代码:
import java.util.Scanner;
public class InputExample {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
String name1 = scan.nextLine();
String name2 = scan.nextLine();
int num1 = scan.nextLine();
double num2 = scan.nextLine();
System.out.println("Employee Name:" + name2 + name1);
System.out.println("Age:" + num1);
System.out.println("Salary:" + (double)num2);
}
}
显示的错误是:
[File:/InputExample.java Line:9,Column:25]需要不兼容的类型:int found:java.lang.String
[File:/InputExample.java Line:10,Column:28]需要不兼容的类型:double found:java.lang.String