Sample program for Recieve user input using Scanner class.
Here’s a Java program that Recieve user input using Scanner class ( name & age ) and prints out a greeting message:
import java.util.Scanner;
public class Main{
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.print("Enter your name: ");
String name = scanner.nextLine();
System.out.print("Enter your age: ");
int age = scanner.nextInt();
System.out.println("Hello, " + name + "! You are " + age + " years old.");
}
}
In this program, we create a new Scanner object scanner
that reads input from the console. We then prompt the user to enter their name and age using System.out.print
, and read their responses using scanner.nextLine()
and scanner.nextInt()
, respectively.
Finally, we use System.out.println
to print out a greeting message that includes the user’s name and age. The +
operator is used to concatenate the various strings and variables in the message.
You can run above all code here just copy and paste.
You really make it seem really easy together with your presentation but I find this topic to be really one thing that I think I’d never understand. It sort of feels too complex and extremely extensive for me. I’m having a look forward for your subsequent submit, I抣l try to get the dangle of it!
Thanks for support
Please provide me with more details on the topic