Advertisement
Guest User

Untitled

a guest
Jul 24th, 2017
46
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.85 KB | None | 0 0
  1. Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 0
  2. at Program.main(Program.java:25)
  3.  
  4. import java.util.Scanner;
  5. public class Program{
  6. static int n;
  7. static int x = 1;
  8. static int [] arr = new int[n];
  9. static int q = 0;
  10. static int g = 0;
  11. static int p = 1;
  12. static int count;
  13.  
  14.  
  15. public static void main(String[] args){
  16.  
  17. Scanner scan = new Scanner(System.in);
  18. int n = scan.nextInt();
  19.  
  20. while(x <= n){
  21.  
  22. arr [q] = p; //assigns value to each array index
  23. g = n%arr[q]; // stores value of remainder
  24. q++;
  25. p++;
  26. x++;
  27. if (g == 0){ //counts and displays each time remainder = 0
  28. count++;
  29. System.out.println(q);
  30. }
  31.  
  32. }
  33.  
  34. System.out.println(count + " Divisors");
  35.  
  36.  
  37. }
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement