
write a program in Java to display the names and roll numbrs of students. Initialize respective array variables for 10 students. Handle ArrayIndexOutOfBoundsException, so that any such problem doesn't cause illegal terminations of program.

import java.util.*;
class Student{
public static void main(String ar[])throws Exception {
int no=0;
Scanner input=new Scanner(System.in);
System.out.print("Enter number of Students: ");
no=input.nextInt();
if(no>10){
throw new Exception("Maximum Students should be ten!\n");
}
else{
int roll[]=new int[no];
String names[]=new String[no];
for(int i=0;i<roll.length;i++){
System.out.print("Enter registration no : ");
roll[i]=input.nextInt();
System.out.print("Enter name : ");
names[i]=input.next();
}
System.out.println("Reg No Name");
for(int i=0;i<roll.length;i++){
System.out.println(roll[i]+" \t"+names[i]);
}
}
}
}
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.