Voglio ottenere input da stdin in per diricevendo input da stdin
3
10 20 30
il primo numero è la quantità di numeri nella seconda riga. Ecco cosa ho ottenuto, ma è bloccato nel ciclo while ... quindi credo. Ho eseguito in modalità di debug e l'array non sta ottenendo assegnare alcun valore ...
import java.util.*;
public class Tester {
public static void main (String[] args)
{
int testNum;
int[] testCases;
Scanner in = new Scanner(System.in);
System.out.println("Enter test number");
testNum = in.nextInt();
testCases = new int[testNum];
int i = 0;
while(in.hasNextInt()) {
testCases[i] = in.nextInt();
i++;
}
for(Integer t : testCases) {
if(t != null)
System.out.println(t.toString());
}
}
}
grazie .. per qualche motivo funziona con il ciclo for; tuttavia non funziona con il ciclo while .. anche dopo aver aggiunto la condizione – miatech