0

Hello everyone !

My program is not working how It is supposed to and I dont know why. Thanks for any feedback.

This is my task: Write the code that finds the number of array elements that are divisible by 8 in a given integer array of 10 elements specified at the input. The array elements are given one at a time, always in a new line.

And this is my solution:

import java.util.Scanner; public class JavaApp {

public static void main(String[] args) {
   Scanner vstup = new Scanner(System.in);
   int pole [] = new int [vstup.nextInt()];
   int i;
  
  for (i=0;i<pole.length;i++) {
    pole[i]=vstup.nextInt();
  } 
   int osem=0;
   for (i=0;i<pole.length;i++) {
    if (pole[i]%8==0) {
      osem++;    
    }
  }
 System.out.println(osem);
} }
  • what is the result you are getting? – VFX Nov 08 '20 at 12:57
  • Please show your compile time error/s. Thanks – John Hanlon Nov 08 '20 at 13:18
  • Exception in thread "main" java.util.NoSuchElementException at java.base/java.util.Scanner.throwFor(Scanner.java:937) at java.base/java.util.Scanner.next(Scanner.java:1594) at java.base/java.util.Scanner.nextInt(Scanner.java:2258) at java.base/java.util.Scanner.nextInt(Scanner.java:2212) at JavaApp.main(JavaApp.java:10) – LosHejkos Nov 08 '20 at 13:26
  • Do you have this issue in some online Java compiler? – Nowhere Man Nov 08 '20 at 13:30

0 Answers0