Advertisement
Felanpro

övning88

Nov 19th, 2020
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.62 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. *
  11. * @author Felix 1
  12. */
  13. public class Övning88 {
  14.  
  15. /**
  16. * @param args the command line arguments
  17. */
  18. public static void main(String[] args) {
  19. Scanner inmatning = new Scanner(System.in);
  20. char fortsätt = 'j';
  21. int tal1 = 0;
  22. int tal2 = 0;
  23. int räknesätt;
  24. int resultat = 0;
  25.  
  26. do
  27. {
  28. System.out.print("Tal 1: "); tal1 = inmatning.nextInt();
  29. System.out.print("Tal 2: "); tal2 = inmatning.nextInt();
  30. System.out.print("Räknesätt (1.+ 2.- 3.* 4./): "); räknesätt = inmatning.nextInt();
  31. switch(räknesätt)
  32. {
  33. case 1:
  34. resultat = tal1 + tal2;
  35. break;
  36.  
  37. case 2:
  38. resultat = tal1 - tal2;
  39. break;
  40.  
  41. case 3:
  42. resultat = tal1 * tal2;
  43. break;
  44.  
  45. case 4:
  46. resultat = tal1 / tal2;
  47. break;
  48. default:
  49. }
  50.  
  51. System.out.println("Resultat: " + resultat);
  52.  
  53. System.out.println("Fortsätt (j/n): ");
  54. fortsätt = inmatning.next().charAt(0);
  55. }
  56. while(fortsätt == 'j');
  57. }
  58.  
  59. }
  60.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement