0

Can we write a method to get user input and return it as a string to use later?

15th Aug 2016, 8:21 AM
Fernando Francis
Fernando Francis - avatar
3 Answers
+ 1
yes we can. actually the code giving output as "hello world" is an example of your doubt.
16th Aug 2016, 5:03 AM
Manisha Bandagi
Manisha Bandagi - avatar
+ 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); }
20th Aug 2016, 6:36 PM
Satyam Abhishek Karn
Satyam Abhishek Karn - avatar
0
@satyam. Did you create a function for user input there? Also, are functions declared outside of main?
27th Aug 2016, 10:45 PM
Francis Dominiko
Francis Dominiko - avatar