Upload files to "Aufgaben/PTP_1"

This commit is contained in:
2025-07-29 08:25:28 +02:00
parent e55131f032
commit 0c9a984a51
5 changed files with 124 additions and 0 deletions

36
Aufgaben/PTP_1/J05A2.java Normal file
View File

@@ -0,0 +1,36 @@
import java.util.Arrays;
public class J05A2 {
public static void main(String args[]){
int zahlen[] = {13, 9, 67, 42, 101, 99, 97, 112, 83, 5, 78};
// a)
for (int i = 0; i < zahlen.length; i++) {
System.out.println("Zahl Nr. " + (i+1) + " lautet " + zahlen[i]);
}
for (int zahl: zahlen ) {
System.out.println(zahl);
}
// b)
for (int i = 0; i < zahlen.length; i++) {
if (i < zahlen.length - 1) {
System.out.print(zahlen[i] + " - ");
} else {
System.out.println(zahlen[i]);
}
}
// c)
Arrays.sort(zahlen);
for (int zahl: zahlen ) {
System.out.println(zahl);
}
System.out.println("Kleinstes Element: " + zahlen[0]);
System.out.println("Größtes Element: " + zahlen[zahlen.length - 1]);
}
}