Write Java code to take user input

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

  1. public class UserInputExample {
  2. public static void main(String[] args) {
  3. Scanner scanner = new Scanner(System.in);
  4. 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

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top