int [] value = new int[5];
int a = 0;
Scanner sc = new Scanner(System.in8);
while(a<value.length){
value[a] = sc.nextInt();
if(value[a]==42){
break;
}
System.out.println(value[a]);
a++;
}

  • created

    Mar '22
  • last reply

    Mar '22
  • 1

    reply

  • 648

    views

  • 2

    users

  • 2

    links

The 42 suggests this is for TEST7?

Does the problem description say there will only be five values? The example input is just that - an example. The real test cases could be much different. When solving problems, try not to assume anything and don’t rely on anything not stated in the problem description.