Advertisement
Guest User

Untitled

a guest
Feb 16th, 2019
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.76 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class Main {
  4. public static void main(String[] args) {
  5. Scanner t=new Scanner(System.in);
  6.  
  7. int which_one;//Which method to use
  8.  
  9. do{
  10. which_one=t.nextInt();
  11. }while(which_one!=1 && which_one!=2);//User can either choose method 1 or 2
  12.  
  13. ///
  14. int chosenMethod();
  15. /////
  16. switch(which_one){
  17. case 1:
  18. chosenMethod=method1;
  19. break;
  20. case 2:
  21. chosenMethod=method2;
  22. break;
  23. }
  24.  
  25. System.out.print(chosenMethod());
  26.  
  27. }
  28. private int method1(){
  29. return 1;
  30. }
  31. private int method2(){
  32. return 2;
  33. }
  34.  
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement