Java is one of the most widely used programming languages for application development, system development, game development, etc. Due to its platform independence and the multiple other features it offers, it is the first choice for people who want to learn programming.
STEPS
- public class UserInputExample {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- System.out.print(“Enter your name: “);
CODE
import java.util.Scanner;
class Main {
public static void main(String[] args) {
Scanner myObj = new Scanner(System.in);
String userName;
System.out.println(“Enter username”);
userName = myObj.nextLine();
System.out.println(“Username is: “ + userName);
}
}
OUTPUT
Enter username
Username is: prasanna