A novice student record system
Main:

import java.util.Scanner;

class Main {

    public static void main(String[] args) {

        Scanner scanner = new Scanner(System.in);
        Student[] students = StudentRoll.gatherStudents(scanner);
        StudentRoll.printStudents(students);

    }
}


Student:

class Student {

    private int rollNumber;
    private String name;

    Student(int rollNumber, String name) {
        this.rollNumber = rollNumber;
        this.name = name;
    }

    int getRollNumber() {
        return rollNumber;
    }
    void setRollNumber(int rollNumber) {
        this.rollNumber = rollNumber;
    }

    String getName() {
        return name;
    }
    void setName(String name) {
        this.name = name;
    }
}


StudentRoll:

class StudentRoll {

    static Student[] gatherStudents(Scanner scanner){

        System.out.print("Number of students? ");
        int numberOfStudents = scanner.nextInt();

        System.out.println("Enter those " + numberOfStudents + " students one by one");
        Student[] students = new Student[numberOfStudents];

        for (int index = 0; index &lt; numberOfStudents; index++) {
            System.out.println("Enter details for the next student no. ");
            System.out.print("Enter Name: ");
            String studentName = scanner.next();
            System.out.print("Enter Roll Number: ");
            int rollNumber = scanner.nextInt();
            students[index] = new Student(rollNumber, studentName);
            System.out.println("\n");
        }
        return students;
    }

    static void printStudents(Student[] students){
        int i = 1;
        for (Student x : students) {
            System.out.println("Student Number : " + i);
            System.out.println("Name -&gt; " + x.getName());
            System.out.println("Roll Number -&gt; " + x.getRollNumber() + "\n");
            i++;
        }
    }
}


I can't post many notes right now, but will as soon as I can. Think the main thing here is that your code isn't very object-oriented, but Java is an object-oriented language. It's also generally a good idea to name variables something other than num, so that when you're working on a method that has 5 different int variables, you aren't tempted to call them num1 , num2, etc., but what they actually represent. I'm also not a big fan of using a for-in when you reference an index, but it didn't seem like the worst thing in the world so I left it in there.