0
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?

2
  • Please provide a complete code example which reproduces the error exactly. The code you have given does not have a class or method which causes other compiler errors other than what you are asking about. Also, the code given does not match the code shown in the error message. Commented Aug 24, 2014 at 3:47
  • and please change the title of the question. Commented Aug 24, 2014 at 3:58

2 Answers 2

4

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 );
Sign up to request clarification or add additional context in comments.

Comments

0

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.