-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathIndexArray.java
More file actions
30 lines (24 loc) · 816 Bytes
/
Copy pathIndexArray.java
File metadata and controls
30 lines (24 loc) · 816 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
package Array;
import java.util.Scanner;
public class IndexArray {
public static final int NUMERO_DI_ELEMENTI = 10;
public static void main(String args[]) {
System.out.println("Inserire una lista di interi non negativi.");
System.out.println("Terminare la sequenza con un numero negativo.");
int[] lista = new int[NUMERO_DI_ELEMENTI];
Scanner tastiera = new Scanner(System.in);
int numero = tastiera.nextInt();
int i = 0;
while (numero >= 0) {
lista[i] = numero;
i++;
numero = tastiera.nextInt();
}
print(lista);
}
public static void print(int[] m) {
for (int i = 0; i < m.length; i++) {
System.out.print(m[i] + " ");
}
}
}