Program to Print Student Details in Java

Here is a java program to print student details using object oriented approach. In this program first the user input the asked details about student. After that the student details are shown in a appropriate format.

Input & print student details in java

//print student details in java
import java.util.Scanner;
class Student{
    void getDetails(){
        Scanner sc = new Scanner(System.in);
        System.out.println("***Input the asked details***");
        System.out.println("Enter Roll Number:");
        int rollNo = sc.nextInt(); 
        
        System.out.println("Enter Name:");
        String name = sc.next();
        
        System.out.println("Enter Age:");
        int age = sc.nextInt();
        
        System.out.println("Enter City:");
        String city = sc.next();
        
        System.out.println("Enter Course:");
        String course = sc.next();
        
        System.out.println("***Inputed Student Details***");
        System.out.println("Roll Number:"+rollNo);
        System.out.println("Name:"+name);
        System.out.println("Age:"+age);
        System.out.println("City:"+city);
        System.out.println("Course:"+course);
    }
}

class Main{
    public static void main(String[] args) {
        Student st = new Student();
        st.getDetails();
    }
}

Input & Output

***Input the asked details***
Enter Roll Number:
1
Enter Name:
xyz
Enter Age:
29
Enter City:
www
Enter Course:
abc
***Inputed Student Details***
Roll Number:1
Name:xyz
Age:29
City:www
Course:abc

Other Java program