String sAge = scan.nextLine();
Scanner scan = new Scanner( System.in );
System.out.print( "what year were you born? >");
int iAge = scan.nextInt (sAge);
final double Cyear = 2014;
final double LEmax = 77.9;
System.out.println( "\nThe percentage of your life you have lived is " + int LEmax );
当我编译它时,我得到这些错误:
C:\Users\PracticeMethods.java:54: error: '.class' expected
System.out.println( "\nThe percentage of your life you have lived is " + int LEmax );
^
C:\Users\PracticeMethods.java:54: error: ';' expected
System.out.println( "\nThe percentage of your life you have lived is " + int LEmax );
我做错了什么?你能帮我解决这些错误吗?
答案 0 :(得分:4)
这只是一个语法错误。试试这个:
System.out.println( "\nThe percentage of your life you have lived is " + LEmax );
请注意,您不必须再次说LEmax
是int
,我们只在声明变量时指定变量的类型,而不是在我们使用时它。或许你打算做演员?如果是这样,那么你应该这样写,围绕()
之间的类型:
System.out.println( "\nThe percentage of your life you have lived is " + (int) LEmax );
答案 1 :(得分:0)
您错误地将LEmax转换为int。 System.out.println( "\nThe percentage of your life you have lived is " + int LEmax );
附近的括号System.out.println( "\nThe percentage of your life you have lived is " + (int) LEmax );
int
代替{{1}}。