SoFunction
Updated on 2025-03-08

Java method to get string input by user

Problem description

Many students, like me, have just started to get into Java, and may suddenly change from C to Java, and some are as helpless as me. How can I get the strings entered by the user!

The columns shown below:

import ; //Import input class 
public static void main(String[] args) {
  
  //Create input object  Scanner sc=new Scanner();
  
  //Get the string entered by the user  String str=null;
  ("Please enter any character:");
  str=();
  
  ("The character you entered is:"+str);
  
 }

The above method of obtaining string input by users in Java is all the content I share with you. I hope you can give you a reference and I hope you can support me more.