Felanpro

övning87

Nov 19th, 2020
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.66 KB | None | 0 0
  1. /*
  2. * To change this license header, choose License Headers in Project Properties.
  3. * To change this template file, choose Tools | Templates
  4. * and open the template in the editor.
  5. */
  6. package skola;
  7. import java.util.Scanner;
  8. /**
  9. *
  10. * @author Felix 1
  11. */
  12. public class Övning87 {
  13.  
  14. /**
  15. * @param args the command line arguments
  16. */
  17. public static void main(String[] args) {
  18. Scanner inmatning = new Scanner(System.in);
  19. char fortsätt = 'j';
  20. int tal1 = 0;
  21. int tal2 = 0;
  22. int räknesätt;
  23. int resultat = 0;
  24. while(fortsätt == 'j')
  25. {
  26. System.out.print("Tal 1: "); tal1 = inmatning.nextInt();
  27. System.out.print("Tal 2: "); tal2 = inmatning.nextInt();
  28. System.out.print("Räknesätt (1.+ 2.- 3.* 4./): "); räknesätt = inmatning.nextInt();
  29. switch(räknesätt)
  30. {
  31. case 1:
  32. resultat = tal1 + tal2;
  33. break;
  34.  
  35. case 2:
  36. resultat = tal1 - tal2;
  37. break;
  38.  
  39. case 3:
  40. resultat = tal1 * tal2;
  41. break;
  42.  
  43. case 4:
  44. resultat = tal1 / tal2;
  45. break;
  46. default:
  47.  
  48. }
  49.  
  50. System.out.println("Resultat: " + resultat);
  51.  
  52. System.out.println("Fortsätt (j/n): ");
  53. fortsätt = inmatning.next().charAt(0);
  54.  
  55. }
  56.  
  57.  
  58. }
  59.  
  60. }
  61.  
Add Comment
Please, Sign In to add comment