Reputation: 1
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 );
When I compile this, I get these errors:
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 );
What am I doing wrong? Can you help me resolve these errors?
Upvotes: 0
Views: 1550
Reputation: 994
You incorrectly casted LEmax to an int. Instead of System.out.println( "\nThe percentage of your life you have lived is " + int LEmax );
do System.out.println( "\nThe percentage of your life you have lived is " + (int) LEmax );
with the parentheses around int
.
Upvotes: 0
Reputation: 235984
It's just a syntax error. Try this:
System.out.println( "\nThe percentage of your life you have lived is " + LEmax );
Notice that you do not have to say again that LEmax
is an int
, we specify the type of a variable only when we declare it, not when we use it. Or perhaps you intended to do a cast? if that's the case, then you should write it like this, surrounding the type between ()
:
System.out.println( "\nThe percentage of your life you have lived is " + (int) LEmax );
Upvotes: 4