0
Input help
I'm trying to make the user put his/her age in the code but I want to do it with a scanner code to make it easier. How would I do this?
3 Respuestas
+ 3
Your code is fine, create a variable name age like
import java.util.Scanner;
class MyClass {
public static void main(String[ ] args) {
int age;
System. out.print("Enter your age\n");
Scanner myVar = new Scanner(System.in);
age = myVar.nextInt();
System.out.println(age);
}
}
your age contains user input value. did I understand your question in right way
+ 1
import java.util.Scanner;
class MyClass {
public static void main(String[ ] args) {
Scanner myVar = new Scanner(System.in);
System.out.println(myVar.nextInt());
}
}
0
where is your code. Have you tried anything yet