96.5k views
14 votes
How can I get multiple user inputs in Java ? I want to be able to use it for subtraction, addition,division and multiplication.For example it should run like

How many numbers do you want to subtract?
4
Enter 4 numbers:
1
2
3
4
result:-8

User Scindix
by
3.1k points

1 Answer

10 votes
You can do something like this :

Scanner sc = new Scanner(System.in);
int[] nums = new int[4];

for(int i = 0; i < nums.length; i++) {
System.out.println("Enter next number: ");
nums[i] = sc.nextInt();
User Ewing
by
3.2k points