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!

6th Mar 2017, 3:54 AM
Shane Miner
Shane Miner - avatar
2 Antworten
0
A+ Thank you very much!
6th Mar 2017, 4:04 AM
Shane Miner
Shane Miner - avatar
+ 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));
6th Mar 2017, 3:59 AM
Nhật Nhật
Nhật Nhật - avatar