VL-Programmieren/VL04/Aufgabe03/Aufgabe03.java

41 lines
770 B
Java
Raw Normal View History

2024-05-13 14:03:58 +00:00
package VL04.Aufgabe03;
/**
* Vorlesung 4 / Aufgabe 3
*
* @author Sebastian Brosch
*/
public class Aufgabe03 {
public static void main(String[] args) {
final int MAXIMUM = 50;
int[] numbers = new int[MAXIMUM];
for (int i = 0; i < numbers.length; i++) {
numbers[i] = i + 1;
}
for (int i = 0; i <= (numbers.length / 2); i++) {
int base = numbers[i];
if (base < 2) {
numbers[i] = 0;
continue;
}
for (int j = i + 1; j < numbers.length; j++) {
int number = numbers[j];
if (number % base == 0) {
numbers[j] = 0;
}
}
}
for (int i = 0; i < numbers.length; i++) {
if (numbers[i] > 0) {
System.out.println(numbers[i]);
}
}
}
}