Stay Tuned!

Subscribe to our newsletter to get our newest articles instantly!

Java Programming

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);
}
}
Avatar

Tuts

About Author

Tutsmaster.org provides tutorials related to tech and programmings. We are also setting up a community for the users and students.

You may also like

introduction to java programming
Java Programming

Java – Introduction, Features, Versions & History

  • December 20, 2020
Java is a general-purpose computer programming language that is concurrent, class-based, object-oriented. Java inherits its object-oriented features from C++. Java
basic terms of java programming
Java Programming

Java – Basic Terms of Java Programming

  • December 20, 2020
A Java program, similar to programs in other programming languages, It also uses the literals, variables, tokens, data types, etc.