Welcome to Westonci.ca, the place where your questions are answered by a community of knowledgeable contributors. Explore our Q&A platform to find reliable answers from a wide range of experts in different fields. Get immediate and reliable solutions to your questions from a community of experienced professionals on our platform.

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