Advertisement
Guest User

Untitled

a guest
Nov 15th, 2019
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.80 KB | None | 0 0
  1. package uebung06;
  2.  
  3. import static pr.MakeItSimple.print;
  4. import static pr.MakeItSimple.println;
  5. import static pr.MakeItSimple.readInt;
  6.  
  7. import pr.MakeItSimple.PRException;
  8.  
  9. public class DividersArrayResult {
  10. public static void main(String[] args) {
  11. println("Ganze Zahl eingeben");
  12. int zahl = readInt();
  13. if (zahl <= 0) {
  14. throw new PRException("Lol");
  15. }
  16. int[] teiler = calculateDividers(zahl);
  17. print("Alle Teiler der Zahl " + zahl + " sind: ");
  18. for (int k = 0; k < teiler.length; k++) {
  19.  
  20. if (teiler[k] != 0) {
  21. print(teiler[k] + " ");
  22. }
  23.  
  24. }
  25. }
  26.  
  27. public static int[] calculateDividers(int zahl) {
  28. int[] teiler = new int[500];
  29. for (int k = 1, p = 0; k <= zahl; k++) {
  30. if (zahl % k == 0) {
  31. teiler[p] = k;
  32. p++;
  33. }
  34. }
  35. return teiler;
  36.  
  37. }
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement