+ 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?
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();
}
}
0
package exe1;
import java.util.Scanner;
static Scnner input =new Scanner(System.in);
public class {
public static void main(String[] args) {