0
Array OutOfBound Error
public class UglyNum { Scanner inp = new Scanner(System.in); int num,count=0; void askNum() { System.out.println("Enter any Number"); num = inp.nextInt(); } int Arr[] = new int[num]; void fact() { for(int i = 2; i <= num; i++) { if(num%i==0) { System.out.println(i); Arr[count]=i; <------------Getting an error here(OutOfBoundation) count++; } } } } class ABC{ <-----------------Main Clas
2 Answers
+ 6
For
int Arr[] = new int[num];
where num is 0, your array has no space allocated to it.
0
How num is 0? I have made a function for taking the value from the User..The size of the array should be the number entered by the user