#What is wrong with this code?

1 messages · Page 1 of 1 (latest)

cosmic idol
#

I'm trying to get the user to input their age and use that number in the final statement being "Your age is "
Bear with me as i am a beginner level coder. Thank you
Java
import java.util.scanner;
public class Exercise2 {
public static void main(String[] args) {
// INSERT YOUR CODE HERE
System.out.print("How old are you?");
int age = scanner.nextInt();
scanner.nextLine();
return age;
System.out.print("Your age is ");
}
}

bleak spruce
#

Pleas read the #📄・posting-guidelines and make sure to follow them.

#

It's important that you format your code properly and add more details.

coarse glacier
#

You must instantiate the Scanner

#

Also be ascertain that the capitalization is congruent with expectations.

cosmic idol
#

I'm not sure what that means sorry

coarse glacier
#

No worries

coarse glacier
#

Also you are returning age which exits your program prematurely, even causing an error. I would advise you to watch a video on system I/o in Java.

https://m.youtube.com/watch?v=huZ1neRqNho&pp=ygUVamF2YSBzY2FubmVyIHR1dG9yaWFs

Java Programming: The Scanner Class in Java Programming
Topics Discussed:

  1. The Scanner Class in Java.
  2. Instantiating a Scanner object in Java.
  3. Input methods of a Scanner object in Java.
  4. Examples of reading the input from the keyboard in Java.

Follow Neso Academy on Instagram: @nesoacademy (https://bit.ly/2XP63OE)

Contribute: http://w...

▶ Play video
cosmic idol
#

Ok thank you

coarse glacier
#

Triumph ever awaits you

cosmic idol
#

This is pretty hard and its not even the hard stuff 😦

bleak spruce
#

If you're a beginner, it's totally normal.

coarse glacier
bleak spruce
#

Just keep practicing

cosmic idol
#

What else would you recommend i do to improve

#

any sites or video channels?

coarse glacier
#

Keep coding watch a bunch of tutorials or read book/website guide (whatever works for you)

Any popular tutorial will help early on