import java.util.Scanner;
class Test1
{
public static void main(String arg[])
{
int s[]=new int[5];
for(int i=0;i<5;i++)
{
Scanner a=new Scanner(System.in);
s[i]=a.nextInt();
}
for(int i=0;i<5;i++)
{
if(s[i]==42)
{
break;
}
System.out.println(s[i]);
}
}
}
Lots of Errors my friend. Scanner class opens a stream for data to be read. Opening another stream would make it read from where the first scanner read which is virtually the end, causing this new scanner to fall apart as it has no next element to read hence causing NZEC.
try using nextInt() alone if you know there are no more elements(as in here). else pair it up with hasNext() method.
Also you are only reading only 5 numbers, the input may have billions of numbers that an array cannot hold (it will run out of memory). and you don’t need to take all the input at once. The input/output at an online judge is in the form of files. So what you do are independent. Either take all input at once or one by one. Similarly output all the results at once or one by one. doesn’t matter.
try this code : http://ideone.com/hF6a1e