Advertisement
Guest User

Bruch

a guest
Feb 17th, 2020
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.01 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 bruch;
  7.  
  8. import java.util.Scanner;
  9.  
  10. /**
  11. *
  12. * @author LipplDom
  13. */
  14. public class Bruch {
  15.  
  16. /**
  17. * @param args the command line arguments
  18. */
  19. public static void main(String[] args) {
  20. int oben, unten, teiler = 0;
  21. Scanner s = new Scanner(System.in);
  22.  
  23. System.out.println("Bruch oben:");
  24. oben = s.nextInt();
  25.  
  26. System.out.println("Bruch unten:");
  27. unten = s.nextInt();
  28.  
  29. if (oben < unten) {
  30. teiler = oben;
  31. } else {
  32. teiler = unten;
  33. }
  34.  
  35. while (oben % teiler != 0 || unten % teiler != 0) {
  36. teiler -= 1;
  37. }
  38.  
  39. oben = oben / teiler;
  40. unten = unten / teiler;
  41.  
  42. System.out.println(oben + "/" + unten);
  43. }
  44.  
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement