0
How can I take the user input from a scanner and use the input as a numerical (double) variable?
How can I take the user input from a scanner and use the input as a numerical (double) variable? //example System.out.println("What is your age?"); Scanner age = new Scanner(System.in); System.out.println(age.nextLine()); System.out.println("You are almost " + (age + 1)); //It's claiming that I can't use equations between scanners and doubles. What's a way //around this? //Thanks!
2 Réponses
0
A+
Thank you very much!
+ 1
you could do something like this:
System.out.println("What is your age?");
Scanner inp = new Scanner(System.in);
double age = inp.nextDouble();
System.out.println("You are almost " + (age + 1));