I have some methods that should incorporate user Input. I put the scanner in the main method, but the values entered by the user are not getting returned, nor getting used in the code. How can I turn the user input into a var that can be accessed by the methods?
for example:
import java.util.Scanner;
public class example {
int variableOne;
int variableTwo;
int variableResultFromUserInput;
public int variableResultFromUserInput(int variableOne, int variableTwo) {
this.variableResultFromUserInput = variableOne * variableTwo;
return this.variableResultFromUserInput;
}
public static void main(String[]args) {
example myexample = new example();
Scanner keyboard = new Scanner(System.in);
System.out.println("What's your variable one? ");
variableOne = keyboard.nextInt(); //this is the variable that causes trouble
System.out.println("Whats your variable two?");
variableTwo = keyboard.hasNextInt(); //this is the second variable that causes trouble
System.out.println(myexample.variableResultFromUserInput); //this is also wrong
}
}