0

How to read more than one numbers in one variable?

11th May 2020, 10:27 AM
Harithra Shanmugam
10 Answers
+ 1
You can put only one value to a variable. If you want to add multiple values to a variable, you can use array.
11th May 2020, 10:47 AM
Bibek Oli
Bibek Oli - avatar
0
Variable or array?
11th May 2020, 10:48 AM
Peace Imion
Peace Imion - avatar
0
Bibek Oli can i get array in scanner?
11th May 2020, 10:49 AM
Harithra Shanmugam
11th May 2020, 10:49 AM
Harithra Shanmugam
0
Please post the code you're trying to debug
11th May 2020, 10:57 AM
Peace Imion
Peace Imion - avatar
11th May 2020, 11:05 AM
Harithra Shanmugam
0
1. Scan for the number of element to store in array, and store it in a variable; 2. Make a while loop to scan for an input, the iterator must be = to number of element, on every loop decrement the iterator by one, and make a conditional break statement when iterator is i-1;
11th May 2020, 11:23 AM
Peace Imion
Peace Imion - avatar
0
King Esteem 🇳🇬 it shows int cannot be converted to int[]
11th May 2020, 12:00 PM
Harithra Shanmugam
0
Go and learn about casting in Java
11th May 2020, 12:24 PM
Peace Imion
Peace Imion - avatar
0
Maybe u can try using an ArrayList: Scanner input = new Scanner(System.in); ArrayList<Integer> list = new ArrayList<Integer>(); for (int i = 1; i <= [NUMBER OF INTEGERS THAT YOU NEED]; i++) { list.add(input.nextInt()); }
11th May 2020, 1:40 PM
wowthecoder
wowthecoder - avatar