0% found this document useful (0 votes)
2 views

Hello Java

The document is a Java program that demonstrates how to take user input using the Scanner class. It prompts the user to enter their name, age, and height, and then displays these values back to the user. This example illustrates basic input handling and output in Java.

Uploaded by

Kumar Shorav
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

Hello Java

The document is a Java program that demonstrates how to take user input using the Scanner class. It prompts the user to enter their name, age, and height, and then displays these values back to the user. This example illustrates basic input handling and output in Java.

Uploaded by

Kumar Shorav
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 1

import java.util.

Scanner;

public class UserInputExample {


public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);

// Taking a string input from the user


System.out.print("Enter your name: ");
String name = scanner.nextLine();

// Taking an integer input from the user


System.out.print("Enter your age: ");
int age = scanner.nextInt();

// Taking a double input from the user


System.out.print("Enter your height in meters: ");
double height = scanner.nextDouble();

// Displaying the input values


System.out.println("Hello, " + name + "!");
System.out.println("You are " + age + " years old.");
System.out.println("You are " + height + " meters tall.");
}
}

You might also like