feat: Ermögliche die Addition mehrerer Ganzzahlen
parent
423283c511
commit
e94a5c5242
|
@ -4,6 +4,21 @@ public class Main {
|
|||
|
||||
public static void main(String[] args) {
|
||||
System.out.println("Hallo Welt!");
|
||||
|
||||
Main m = new Main();
|
||||
|
||||
System.out.println();
|
||||
System.out.printf("Die Summe von %d + % d = %d", 3, 8, m.add(3, 8));
|
||||
System.out.printf("Es geht noch besser: %d + %d + %d = %d", 2, 5, 9, m.add(2, 5, 9));
|
||||
}
|
||||
|
||||
public int add(int... numbers) {
|
||||
int res = 0;
|
||||
|
||||
for (int n : numbers)
|
||||
res += n;
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue