Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.arithmetique;
- import java.util.Scanner;
- public class Main {
- public static void main(String[] args) {
- Scanner scan = new Scanner(System.in);
- while (true){
- byte opt = 0;
- float fstChoice, secChoice;
- System.out.println();
- System.out.println("1 - Somme de deux réels ");
- System.out.println("2- Soustraction de deux réels");
- System.out.println("3- Multiplication de deux réels");
- System.out.println("4 - Division de deux réels");
- System.out.println("5- Sortie du programme");
- System.out.println();
- while (opt < 1 || opt > 5){
- System.out.println("option: ");
- opt = scan.nextByte();
- }
- if (opt == 5) break;
- System.out.println("premier Choix: ");
- fstChoice = scan.nextFloat();
- if (opt != 4){
- System.out.println("deuxieme Choix: ");
- secChoice = scan.nextFloat();
- }
- else {
- do {
- System.out.println("deuxieme Choix: ");
- secChoice = scan.nextInt();
- } while (secChoice == 0);
- }
- float res = switch (opt) {
- case 1 -> fstChoice + secChoice;
- case 2 -> fstChoice - secChoice;
- case 3 -> fstChoice * secChoice;
- default -> fstChoice / secChoice;
- };
- System.out.println(res);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement