Advertisement
Guest User

ANTOINEROSEFILSDEPUTE

a guest
Nov 20th, 2017
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.15 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class Division {
  4. public static void main(String [] args){
  5.  
  6. Scanner scan = new Scanner(System.in);
  7. System.out.print("Entrez le dividende : ");
  8. int x = scan.nextInt();
  9. scan.nextLine();
  10. System.out.print("Entrez le diviseur : ");
  11. int y = scan.nextInt();
  12. scan.nextLine();
  13. /*System.out.print("Le résultat de la division entière est : ");
  14. System.out.println(x/y);*/
  15.  
  16. int n = 0;
  17. try {
  18. n = x/y;
  19. }
  20. catch(ArithmeticException e){
  21. System.out.print("Division par 0 impossible!\n");
  22. while(n==0){
  23. System.out.print("Entrez de nouveau le diviseur : ");
  24. y = scan.nextInt();
  25. scan.nextLine();
  26. try {
  27. n = x/y;
  28. }
  29. catch(ArithmeticException R){
  30. System.out.print("Division par 0 impossible!\n");
  31. }
  32. }
  33. }
  34. System.out.print("Le résultat de la division entière est : ");
  35. System.out.println(x/y);
  36. }
  37. }
  38.  
  39. //Avec un do{...}while(...); ça aurait été mieux (moins de lignes)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement