Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class Main {
- public static void main(String[] args) {
- Scanner t=new Scanner(System.in);
- int which_one;//Which method to use
- do{
- which_one=t.nextInt();
- }while(which_one!=1 && which_one!=2);//User can either choose method 1 or 2
- ///
- int chosenMethod();
- /////
- switch(which_one){
- case 1:
- chosenMethod=method1;
- break;
- case 2:
- chosenMethod=method2;
- break;
- }
- System.out.print(chosenMethod());
- }
- private int method1(){
- return 1;
- }
- private int method2(){
- return 2;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement