+ 4

How do I implement multiple variables in one scanner code?

I'm trying to implement two variables, money, and age. How do I do this?

13th Nov 2016, 10:18 PM
bdubs5050
bdubs5050 - avatar
2 Respostas
+ 2
If you want to read all in one line then you can ask user to write age and money in same line by separating it with space or with other separator: import java.util.Scanner; public class Application { public static void main(String[] args) { int age, money; Scanner s = new Scanner(System.in); System.out.println("Please enter age and money by separating them with space."); String userInputs[] = s.nextLine().split(" "); age = new Integer(userInputs[0]); money = new Integer(userInputs[1]); System.out.println("You have entered \n age " + age + "\n money " + money); s.close(); } }
14th Nov 2016, 9:56 AM
Levon Hakobyan
Levon Hakobyan - avatar
0
package exe1; import java.util.Scanner; static Scnner input =new Scanner(System.in); public class { public static void main(String[] args) {
18th Nov 2016, 8:21 AM
Morteza
Morteza - avatar