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(); } }
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
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
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);