0
Can we write a method to get user input and return it as a string to use later?
3 ответов
+ 1
yes we can. actually the code giving output as "hello world" is an example of your doubt.
+ 1
yes you can.
public static String input()
{
Scanner sc = new Scanner(System.in);
System.out.println("Enter data ");
String s = sc.next();
return s;
}
public static void main()
{
String use = input();
System.out.println("entered data is : " +use);
}
0
@satyam. Did you create a function for user input there? Also, are functions declared outside of main?