Java program to accept roll no, name of 5 students and display them back on the screen in tabular form.

Java program to accept roll no, name of 5 students and display them back on the screen in tabular form. 


import java.util.Scanner;
class Students{
    int rollNumber;
    String name;
}
public class demo{
    public static void main(String args[]) {
        Scanner sc = new Scanner(System.in);
        Students[] std = new Students[5];
        for(int i=0;i<5;i++){
            std[i] = new Students();
            System.out.print("Enter roll number: ");
            std[i].rollNumber = sc.nextInt();
            sc.nextLine();
            System.out.print("Enter Name: ");
            std[i].name = sc.nextLine();
        }  
        sc.close();
    for(int i=0;i<5;i++){
        System.out.println(std[i].rollNumber+"\t"+std[i].name);
    }
}
}

Comments