Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package uebung06;
- import static pr.MakeItSimple.print;
- import static pr.MakeItSimple.println;
- import static pr.MakeItSimple.readInt;
- import pr.MakeItSimple.PRException;
- public class DividersArrayResult {
- public static void main(String[] args) {
- println("Ganze Zahl eingeben");
- int zahl = readInt();
- if (zahl <= 0) {
- throw new PRException("Lol");
- }
- int[] teiler = calculateDividers(zahl);
- print("Alle Teiler der Zahl " + zahl + " sind: ");
- for (int k = 0; k < teiler.length; k++) {
- if (teiler[k] != 0) {
- print(teiler[k] + " ");
- }
- }
- }
- public static int[] calculateDividers(int zahl) {
- int[] teiler = new int[500];
- for (int k = 1, p = 0; k <= zahl; k++) {
- if (zahl % k == 0) {
- teiler[p] = k;
- p++;
- }
- }
- return teiler;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement