Westonci.ca connects you with experts who provide insightful answers to your questions. Join us today and start learning! Explore comprehensive solutions to your questions from knowledgeable professionals across various fields on our platform. Connect with a community of professionals ready to provide precise solutions to your questions quickly and accurately.

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


Sagot :

nunoz
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();