0

What am I doing wrong here? I’m trying to use three methods to echo input from a user

Here is my code so far. Any suggestions? import java.util.Scanner; public class GetInput { public static String GetInput() { Scanner input = new Scanner(System.in); String text= input.nextLine(); return text; } public static void PrintToConsole() { System.out.println("You entered: " + text); } public static void main(String[] args) { System.out.println("Enter any value: "); GetInput(); PrintToConsole(); } }

13th May 2019, 8:31 AM
Tracy Lester
3 Answers
0
the text variables is only in the GetInput() method, the PrintToConsole() method doesn't have text variable. If u want to use the text variable for both method then u should make a variable for the whole class or make the PrintToConsole() method to have parameter
13th May 2019, 8:52 AM
Randy Hidayah
Randy Hidayah - avatar
0
im try to have three totally separate methods but some how take in for example ask the user for their name using a GetInput method and then print the name onto the console but using a print method
13th May 2019, 9:02 AM
Tracy Lester
0
You can make the PrintToConsole() method have a local variable called text with content that you get from the GetInput() text = GetInput(); System.out.println(text);
13th May 2019, 9:12 AM
Randy Hidayah
Randy Hidayah - avatar