0

How can I make input for 5 and more numbers?

I need to make a program which have an input of int numbers(5 and more). how can I do that?

15th Sep 2018, 10:37 AM
ITknowledge
ITknowledge - avatar
4 ответов
+ 1
Make an int array and insert values to array using loop
15th Sep 2018, 10:55 AM
Dasun;
Dasun; - avatar
+ 1
I do not know exactly what you try to do but maybe something like this: public static void main(String[] args){ Scanner scan = new Scanner(System.in); System.out.print("Amount of number? "); int num = scan.nextInt(); int[] arr = new int[num]; for(int i = 0; i < arr.length; i++){ System.out.print("Enter number at position: "+ (i+1)+ " "); arr[i] = scan.nextInt(); } for (int i = 0; i < arr.length; i++) { System.out.print("My numbers and their positions " + (i+1) + ": "); System.out.print(arr[i] + "\n"); } } Dont forget to import the Scanner
15th Sep 2018, 12:46 PM
JavaBobbo
JavaBobbo - avatar
+ 1
javaBobbo Thank you. it's exactly what I need. +like
15th Sep 2018, 6:55 PM
ITknowledge
ITknowledge - avatar
0
No problems mate
15th Sep 2018, 8:16 PM
JavaBobbo
JavaBobbo - avatar