Hi Have written this code to solve TEST Problem
and it keeps on giving Run time Error unamused
Please help me am Stuck with this
It works fine on my Ecllipse..

import java.util.Scanner;
public class Main {
public static void main (String args[])
{
int i=1;
int []anArray;
anArray = new int[100];
while (true)
{
Scanner scanner = new Scanner(System.in);
anArray[i] = scanner.nextInt();
if((anArray[i])==42)
{
break;
}
i++;
}
for (int pos=1;pos {
System.out.println(anArray[pos]);
}
}
}

  • created

    Jan '11
  • last reply

    Jan '11
  • 1

    reply

  • 192

    views

  • 1

    user

i could solve this error after keeping Scanner statement out of the while loop
as it was creating multiple instances which is not necessary bulb

Suggested Topics

Want to read more? Browse other topics in JAVA based languages or view latest topics.