Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
- package exocalculatrice;
- import java.util.Scanner;
- /**
- *
- * @author Benjamin
- */
- public class ExoCalculatrice {
- /**
- * @param args the command line arguments
- */
- public static void main(String[] args) {
- boolean nouveauCalcul = true;
- int demandeCalcul;
- Scanner clavier = new Scanner(System.in);
- while (nouveauCalcul == true) {
- int choix;
- System.out.println("Veuillez choisir une opération a effectuer :\n 1) Addition(+) \n 2) Soustraction(-) \n 3) Multiplication \n 4) Division(/) (Entrez le choix correspondant à votre choix)");
- choix = clavier.nextInt();
- switch (choix) {
- case 1:
- int nombreAdd1;
- int nombreAdd2;
- int resultatAdd;
- System.out.println("Vous avez choisis l'Addition, veuillez entrer le premier nombre entier à additionner :");
- nombreAdd1 = clavier.nextInt();
- System.out.println("veuillez choisir un second entier à additionner :");
- nombreAdd2 = clavier.nextInt();
- resultatAdd = nombreAdd1 + nombreAdd2;
- System.out.println(nombreAdd1 + "+" + nombreAdd2 + "=" + resultatAdd);
- break;
- case 2:
- int nombreSous1;
- int nombreSous2;
- int resultatSous;
- System.out.println("Vous avez choisis la Soustraction, veuillez entrer le premier nombre entier à soustraire :");
- nombreSous1 = clavier.nextInt();
- System.out.println("veuillez choisir un second entier à soustraire :");
- nombreSous2 = clavier.nextInt();
- resultatSous = nombreSous1 - nombreSous2;
- System.out.println(nombreSous1 + "-" + nombreSous2 + "=" + resultatSous);
- break;
- case 3:
- int facteur1;
- int facteur2;
- int produit;
- System.out.println("Vous avez choisis la Multiplication, veuillez entrer le premier facteur :");
- facteur1 = clavier.nextInt();
- System.out.println("veuillez choisir le second facteur :");
- facteur2 = clavier.nextInt();
- produit = facteur1 * facteur2;
- System.out.println(facteur1 + "*" + facteur2 + "=" + produit);
- break;
- case 4:
- int dividande;
- int diviseur;
- double quotient;
- System.out.println("Vous avez choisis la Division, veuillez entrer le dividande :");
- dividande = clavier.nextInt();
- System.out.println("veuillez choisir le diviseur :");
- diviseur = clavier.nextInt();
- if (diviseur != 0) {
- quotient = (double) dividande / diviseur;
- System.out.println(dividande + "/" + diviseur + "=" + quotient);
- } else {
- System.err.println("MAIS VOUS ÊTES FOU !!! UNE DIVISION PAR ZERO MAIS C EST N IMPORTE QUOI ! AU BUCHER !");
- }
- break;
- default:
- System.err.println("Entrée invalide");
- break;
- }
- if (choix == 1 || choix == 2 || choix == 3 || choix == 4) {
- System.out.println("Voulez vous lancer un nouveau calcul? \n 1) Oui \n 2) Non (Entrez le choix correspondant à votre choix)");
- demandeCalcul = clavier.nextInt();
- if (demandeCalcul == 1) {
- nouveauCalcul = true;
- } else {
- System.out.println("A bientot");
- nouveauCalcul = false;
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement