Advertisement
mmouhib

haroun yfz

Oct 10th, 2021
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.75 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.         while (true){
  9.             Scanner scan = new Scanner(System.in);
  10.             byte opt = 0;
  11.             float fstChoice, secChoice;
  12.             System.out.println();
  13.             System.out.println("1 - Somme de deux réels ");
  14.             System.out.println("2- Soustraction de deux réels");
  15.             System.out.println("3- Multiplication de deux réels");
  16.             System.out.println("4 - Division de deux réels");
  17.             System.out.println("5- Sortie du programme");
  18.             System.out.println();
  19.             while (opt < 1 || opt > 5){
  20.                 System.out.println("option: ");
  21.                 opt = scan.nextByte();
  22.             }
  23.             if (opt == 5) break;
  24.             System.out.println("premier Choix: ");
  25.             fstChoice = scan.nextInt();
  26.             if (opt != 4){
  27.                 System.out.println("deuxieme Choix: ");
  28.                 secChoice = scan.nextInt();
  29.             }
  30.             else {
  31.                 do {
  32.                     System.out.println("deuxieme Choix: ");
  33.                     secChoice = scan.nextInt();
  34.                 } while (secChoice == 0);
  35.             }
  36.             float res;
  37.             switch (opt){
  38.                 case 1:
  39.                     res = fstChoice + secChoice;
  40.                     break;
  41.                 case 2:
  42.                     res = fstChoice - secChoice;
  43.                     break;
  44.                 case 3:
  45.                     res = fstChoice * secChoice;
  46.                     break;
  47.                 default:
  48.                     res = fstChoice / secChoice;
  49.             }
  50.             System.out.println(res);
  51.         }
  52.     }
  53. }
  54.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement