I am getting exception Array Index Out of Bounds error. I am declaring integer i, j. Taking the input from the user how many character he wanted to insert in array. Which is in "i". Now within "j" I asked user to insert the character. Now within loop depending upon the value of j one by one value have to be inserted inside "ch".
import java.util.Scanner;
class EvenOddInArray
{
public static void main(String arg[]){
int i, j;
System.out.println("Enter no of integer you wanted to input");
Scanner obj1 = new Scanner(System.in);
j = obj1.nextInt();
System.out.println("Enter a char");
Scanner obj = new Scanner(System.in);
char ch[] = new char[j] ;
for(i=0;i<j;i++){
ch[i] = obj.next().charAt(i);
}
}
}
]2