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?
4 ответов
+ 1
Make an int array and insert values to array using loop
+ 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
+ 1
javaBobbo Thank you. it's exactly what I need. +like
0
No problems mate