Java- Program to Take Input and Display

Program to Take Input and Display

Write a Java program to take input from user as “Name” and Display as “Hello Name” Input Your This program is done by using Scanner class to use Scanner class you have to import page called Scanner import java.util.Scanner;

Java Scanner class is used to enable keyboard for input operations

Scanner obj_name = new Scanner(System.in);

import java.util.Scanner;

public class PrintHelloName {
public static void main(String[] args) {
Scanner myname = new Scanner(System.in);
System.out.println("Enter Your Name:");
String name = myname.nextLine();
System.out.println("Hello Your name is :"+name);
}

}

This program is done by using the Swing framework of java. Here you have to import JOptionPane package from swing directory to do this operation.

It will take input from input dialog box and will show output on console.

String name = JOptionPane.showInputDialog(“name”);

import javax.swing.JOptionPane;

public class PrintHelloName {
public static void main(String[] args) {
String name;
name = JOptionPane.showInputDialog("name");
System.out.println("Hello Your Name is : "+name);
}
}