add 3/4 and 4/1, 4/2

This commit is contained in:
Matti 2024-04-10 13:59:03 +02:00
parent 6345534e84
commit 27f1bffb3b
3 changed files with 85 additions and 0 deletions

31
src/part3/aufg4.java Normal file
View File

@ -0,0 +1,31 @@
package part3;
public class aufg4 {
public static void main(String[] args){
int i = 5;
int j = 3;
boolean b = false;
// a) (!((i<j) && b))
// bool true
// b) i/j
// int 1
// c) (float) (i/j)
// float 1.6667 ?
// d) (float) i/j
// float 1.6667 ?
// e) (float) i / (float) j
// float 1.6667 ?
// f) ((i++ == 5) || (--i == 5))
// bool true
// g) ((i++ == 5) | (--i == 5))
// error ?
}
}

20
src/part4/aufg1.java Normal file
View File

@ -0,0 +1,20 @@
package part4;
public class aufg1 {
public static void main(String[] args){
int MAXIMUM = 42;
for(int i = 1; i < MAXIMUM; i++){
if(i % 2 == 0){
System.out.println(i);
}
}
System.out.println("=================");
System.out.println("=================");
for(int i = MAXIMUM; i > 1; i--){
if(i % 2 == 1){
System.out.println(i);
}
}
}
}

34
src/part4/aufg2.java Normal file
View File

@ -0,0 +1,34 @@
package part4;
public class aufg2 {
public static void main(String[] args){
int sum = 0;
for(int i = 1; i<21; i++){
sum += i;
System.out.println("the sum of the first " + i + " integers is: " + sum);
}
System.out.println("========================================");
sum = 0;
int i = 1;
while(i<21){
sum += i;
System.out.println("the sum of the first " + i + " integers is: " + sum);
i++;
}
System.out.println("========================================");
sum = 0;
i = 0;
do{
sum += i;
System.out.println("the sum of the first " + i + " integers is: " + sum);
i++;
}while (i<21);
}
}