Advertisement
mmouhib

TP Java 1

Oct 11th, 2021
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.57 KB | None | 0 0
  1. package com.arithmetique;
  2.  
  3. import java.util.Scanner;
  4.  
  5. public class Main {
  6.  
  7. public static void main(String[] args) {
  8. Scanner scan = new Scanner(System.in);
  9. while (true){
  10. byte opt = 0;
  11. float fstChoice, secChoice;
  12.  
  13. System.out.println();
  14. System.out.println("1 - Somme de deux réels ");
  15. System.out.println("2- Soustraction de deux réels");
  16. System.out.println("3- Multiplication de deux réels");
  17. System.out.println("4 - Division de deux réels");
  18. System.out.println("5- Sortie du programme");
  19. System.out.println();
  20.  
  21. while (opt < 1 || opt > 5){
  22. System.out.println("option: ");
  23. opt = scan.nextByte();
  24. }
  25. if (opt == 5) break;
  26.  
  27. System.out.println("premier Choix: ");
  28. fstChoice = scan.nextFloat();
  29. if (opt != 4){
  30. System.out.println("deuxieme Choix: ");
  31. secChoice = scan.nextFloat();
  32. }
  33. else {
  34. do {
  35. System.out.println("deuxieme Choix: ");
  36. secChoice = scan.nextInt();
  37. } while (secChoice == 0);
  38. }
  39. float res = switch (opt) {
  40. case 1 -> fstChoice + secChoice;
  41. case 2 -> fstChoice - secChoice;
  42. case 3 -> fstChoice * secChoice;
  43. default -> fstChoice / secChoice;
  44. };
  45. System.out.println(res);
  46. }
  47. }
  48. }
  49.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement