16.01.2025

This commit is contained in:
Dominik 2025-01-16 11:11:21 +00:00
commit df9f5fc94c
5 changed files with 97 additions and 0 deletions

3
.gitignore vendored Normal file
View file

@ -0,0 +1,3 @@
*.class
*.jar
.devcontainer

View file

@ -0,0 +1,24 @@
package de.dhbwka.java.exercise.datatypes;
class Round {
public static void main(String[] args) {
double pi = 3.1415926;
double e = 2.7182818;
int piInt = Round.round(pi);
int eInt = Round.round(e);
System.out.println("Pi: " + pi + " gerundet: " + piInt);
System.out.println("e: " + e + " gerundet: " + eInt);
int negativePiInt = Round.round(-pi);
int negativeEInt = Round.round(-e);
System.out.println("Pi: " + -pi + " gerundet: " + negativePiInt);
System.out.println("e: " + -e + " gerundet: " + negativeEInt);
}
private static int round(double number) {
return (int) (number % 1 >= 0.5 ? number + 1 : number % 1 <= -0.5 ? number - 1 : number);
}
}

View file

@ -0,0 +1,29 @@
package de.dhbwka.java.exercise.operators;
public class Easter {
public static void main(String[] args) {
System.out.println("Jahr:");
java.util.Scanner scan = new java.util.Scanner(System.in);
int jahr = scan.nextInt();
scan.close();
int a = jahr % 19;
int b = jahr % 4;
int c = jahr % 7;
int k = jahr / 100;
int p = (8 * k + 13) / 25;
int q = k / 4;
int m = (15 + k - p - q) % 30;
int n = (4 + k - q) % 7;
int d = (19 * a + m) % 30;
int e = (2 * b + 4 * c + 6 * d + n) % 7;
int ostern = 22 + d + e;
if (ostern > 31) {
ostern -= 31;
System.out.println("Ostern: " + ostern + ". April " + jahr);
} else {
System.out.println("Ostern: " + ostern + ". März " + jahr);
}
}
}

View file

@ -0,0 +1,19 @@
package de.dhbwka.java.exercise.operators;
public class IncrementDecrement {
public static void main(String[] args) {
int i = 0; // i = 0
int j = 0; // j = 0
j = ++i; // j = 1, i = 1
int k = j++ + ++i; // k = 1 + 2 = 3, j = 2, i = 2
System.out.println("k: " + k); // k: 3
System.out.println("*: " + j++ + ++i); // *: 23
System.out.println(j++ + ++i); // 7
int m = j++ * ++i; // m = 5 * 4 = 21, j = 5, i = 5
System.out.println("m: " + m); // m: 20
int n = --j * --i; // n = 16, j = 4, i = 4
System.out.println("n: " + n); // n: 16
System.out.println("i: " + i); // i: 4
System.out.println("j: " + j); // j: 4
}
}

View file

@ -0,0 +1,22 @@
package de.dhbwka.java.exercise.operators;
public class Priority {
public static void main(String[] args) {
System.out.println("1: " + (5 / 2 * 2)); // 1: 4
System.out.println("2: " + (9. / 2 * 5)); // 2: 22.5
boolean a = true, b = false, c = false;
System.out.println("3: " + (a && b || c)); // 3: false
char ch = 'c';
System.out.println("4: " + ('a' + 1 < ch)); // 4: true
int i = 1, j = 2, k = 3;
System.out.println("5: " + (-i - 5 * j >= k + 1)); // 5: false
i = 1;
if (a || (++i == 2)) {
System.out.println("6: " + i); // 6: 1
}
i = 1;
if (a | (++i == 2)) {
System.out.println("7: " + i); // 7: 2
}
}
}