Advertisement
Guest User

Untitled

a guest
Jan 23rd, 2017
129
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.24 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 exocalculatrice;
  7.  
  8. import java.util.Scanner;
  9.  
  10. /**
  11. *
  12. * @author Benjamin
  13. */
  14. public class ExoCalculatrice {
  15.  
  16. /**
  17. * @param args the command line arguments
  18. */
  19. public static void main(String[] args) {
  20. boolean nouveauCalcul = true;
  21. int demandeCalcul;
  22. Scanner clavier = new Scanner(System.in);
  23.  
  24. while (nouveauCalcul == true) {
  25. int choix;
  26.  
  27. 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)");
  28.  
  29. choix = clavier.nextInt();
  30.  
  31. switch (choix) {
  32.  
  33. case 1:
  34. int nombreAdd1;
  35. int nombreAdd2;
  36. int resultatAdd;
  37.  
  38. System.out.println("Vous avez choisis l'Addition, veuillez entrer le premier nombre entier à additionner :");
  39. nombreAdd1 = clavier.nextInt();
  40. System.out.println("veuillez choisir un second entier à additionner :");
  41. nombreAdd2 = clavier.nextInt();
  42.  
  43. resultatAdd = nombreAdd1 + nombreAdd2;
  44.  
  45. System.out.println(nombreAdd1 + "+" + nombreAdd2 + "=" + resultatAdd);
  46. break;
  47. case 2:
  48. int nombreSous1;
  49. int nombreSous2;
  50. int resultatSous;
  51.  
  52. System.out.println("Vous avez choisis la Soustraction, veuillez entrer le premier nombre entier à soustraire :");
  53. nombreSous1 = clavier.nextInt();
  54. System.out.println("veuillez choisir un second entier à soustraire :");
  55. nombreSous2 = clavier.nextInt();
  56.  
  57. resultatSous = nombreSous1 - nombreSous2;
  58.  
  59. System.out.println(nombreSous1 + "-" + nombreSous2 + "=" + resultatSous);
  60. break;
  61. case 3:
  62. int facteur1;
  63. int facteur2;
  64. int produit;
  65.  
  66. System.out.println("Vous avez choisis la Multiplication, veuillez entrer le premier facteur :");
  67. facteur1 = clavier.nextInt();
  68. System.out.println("veuillez choisir le second facteur :");
  69. facteur2 = clavier.nextInt();
  70.  
  71. produit = facteur1 * facteur2;
  72.  
  73. System.out.println(facteur1 + "*" + facteur2 + "=" + produit);
  74. break;
  75. case 4:
  76. int dividande;
  77. int diviseur;
  78. double quotient;
  79.  
  80. System.out.println("Vous avez choisis la Division, veuillez entrer le dividande :");
  81. dividande = clavier.nextInt();
  82. System.out.println("veuillez choisir le diviseur :");
  83. diviseur = clavier.nextInt();
  84. if (diviseur != 0) {
  85. quotient = (double) dividande / diviseur;
  86.  
  87. System.out.println(dividande + "/" + diviseur + "=" + quotient);
  88. } else {
  89. System.err.println("MAIS VOUS ÊTES FOU !!! UNE DIVISION PAR ZERO MAIS C EST N IMPORTE QUOI ! AU BUCHER !");
  90. }
  91. break;
  92. default:
  93.  
  94. System.err.println("Entrée invalide");
  95. break;
  96.  
  97. }
  98.  
  99. if (choix == 1 || choix == 2 || choix == 3 || choix == 4) {
  100. System.out.println("Voulez vous lancer un nouveau calcul? \n 1) Oui \n 2) Non (Entrez le choix correspondant à votre choix)");
  101.  
  102. demandeCalcul = clavier.nextInt();
  103.  
  104. if (demandeCalcul == 1) {
  105.  
  106. nouveauCalcul = true;
  107. } else {
  108. System.out.println("A bientot");
  109.  
  110. nouveauCalcul = false;
  111. }
  112. }
  113. }
  114. }
  115. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement