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

26th Jan 2017, 8:27 PM
Divyanshu Bhatnagar
Divyanshu Bhatnagar - avatar
2 Answers
+ 6
For int Arr[] = new int[num]; where num is 0, your array has no space allocated to it.
27th Jan 2017, 1:30 AM
Hatsy Rei
Hatsy Rei - avatar
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
27th Jan 2017, 7:01 AM
Divyanshu Bhatnagar
Divyanshu Bhatnagar - avatar