How to take string input in java?

DWQA QuestionsCategory: QuestionsHow to take string input in java?
Editor Staff asked 3 weeks ago

How to take string input in java?

1 Answers
Editor Staff answered 3 weeks ago

“import java.util.Scanner; // Import the Scanner class
class MyClass {
public static void main(String[] args) {
Scanner myObj = new Scanner(System.in); // Create a Scanner object
System.out.println(“”Enter username””);
String userName = myObj.nextLine(); // Read user input
System.out.println(“”Username is: “” + userName); // Output user input
}
}”