I'm struggling with passing a variable value that a user has entered into my program into a method. I think the technical word is parameters.
The problem I'm having is that after the user enters a number in the getnum()
method I want the number to be passed down to the two methods calculation
and `calculation_two. However, I can't seem to be able to achieve it.
Just to explain the program, the user enters a number in the getnum()
method, then they go to the option method and after they select what option, in the calculations methods the number that was written in the getnum()
method needs to be passed down the the calculations methods. Therefore, I will then be able to perform calculations with it that way. I need the program to be set up like this as well for my own personal reasons.
Can anyone assist please?
Thanks
public static void main (String[]args){
getnum();
}
public static void getnum() {
Scanner input = new Scanner(System.in);
System.out.println("Enter a number: ");
int num = input.nextInt();
option();
}
public static void option() {
Scanner input2 = new Scanner(System.in);
System.out.println("would you like to see option 1 or 2");
int num2 = input2.nextInt();
if(num2==1) {calculation();}
else if(num2==2) {calculation_two();}
else {System.exit(0);}
}
public static void calculation() {
}
public static void calculation_two() {
}