Reputation: 71
I wrote the code as shown:
what more should I include to remove this NoSuchElementFound Exception
I've tried including HasMoreElements(),HasNextInt() but that did'nt work either
Scanner input=new Scanner(System.in);
t=input.nextInt();
while(t>0)
{
int n=input.nextInt();
int a[]=new int[n];
please try to modify this code so that i'll not get this exception.
Upvotes: 1
Views: 53
Reputation: 502
This exception is thrown to indicate that there are no more elements in buffer but your code is expecting one & based on the code that you have shared following two possibilities are expected:-
Hope it helps!
Upvotes: 0
Reputation: 1813
Scanner input = new Scanner(System.in);
while(input.hasNext()){
int n = input.nextInt();
int a[] = new int[n];
...
}
Upvotes: 2
Reputation: 13
i think you need to declare 't'
Scanner input=new Scanner(System.in);
int t=input.nextInt();
while(t>0)
{
int n=input.nextInt();
int a[]=new int[n];
}
Upvotes: 0