📢 Join My WhatsApp Channel JavaWithSumit

Get Daily ICSE Java Notes, Programs & Exam Tips 🚀

👉 Join Now

📘 Java Program to Input and Display User Details in Table Format

 📘 Java Program to Input and Display User Details in Table Format 

In this program, we will take input like name, age, address, mobile number, and email ID and display it in a proper table format.

🧠 Concepts Used

  • Scanner class for input
  • Variables and data types
  • Formatted output using \t (tab space)

🪜 Algorithm

  • Start the program
  • Import the Scanner class
  • Create Scanner object
  • Input the following details:

Name

Age

Address

Mobile Number

Email ID

  • Store values in variables
  • Print table heading
  • Print column names (Name, Age, Address, Mobile, Email)
  • Display all values in one row using tab space
  • Stop the program

💻 Java Program


import java.util.Scanner;

public class UserDetails{

    public static void main(String args[ ]) {

        Scanner sc = new Scanner(System.in);


        // Input Section

        System.out.print("Enter Name: ");

        String name = sc.nextLine();


        System.out.print("Enter Age: ");

        int age = sc.nextInt();

        sc.nextLine(); // clear buffer


        System.out.print("Enter Address: ");

        String address = sc.nextLine();


        System.out.print("Enter Mobile Number: ");

        String mobile = sc.nextLine();


        System.out.print("Enter Email ID: ");

        String email = sc.nextLine();


        // Output Section (Table Format)

        System.out.println("\n==============================================");

        System.out.println("              USER DETAILS TABLE              ");

        System.out.println("==============================================");


        System.out.println("Name\tAge\tAddress\t\tMobile\t\tEmail");

        System.out.println("--------------------------------------------------------------");


        System.out.println(name + "\t" + age + "\t" + address + "\t" + mobile + "\t" + email);


        sc.close();

    }

}

📌 Input


Enter Name: Sumit

Enter Age: 16

Enter Address: Varanasi

Enter Mobile Number: 9876543210

Enter Email ID: sumit@gmail.com

📌 Output

==============================================

          USER DETAILS TABLE

==============================================

Name    Age     Address         Mobile          Email

--------------------------------------------------------------

Sumit   16      Varanasi        9876543210      sumit@gmail.com

🔍 Explanation 

  • \t is used to create space between columns
  • First line prints headings (columns)
  • Second line prints user data in one row
  • This creates a table-like structure in output

Comments

Popular posts from this blog

Introduction to Object Oriented Programming and Java- ICSE Notes

Introduction to OOP's

Object Modelling – Entities and Their Behaviour in Java