Vorlesung 3 / Aufgabe 3

This commit is contained in:
Sebastian Brosch 2024-05-10 08:09:58 +02:00
parent d64c33dfe5
commit 4257cab1fa
2 changed files with 30 additions and 23 deletions

View File

@ -1,23 +0,0 @@
class Aufgabe {
public static void main(String[] args) {
// Die drei Zahlen für die Prüfung definieren.
int a = 3;
int b = 4;
int c = 5;
// Die Zahlen überprüfen und das Ergebnis ausgeben.
System.out.println("Werte entsprechen dem Satz des Pythagoras: " + (check(a,b,c) ? "Ja" : "Nein"));
}
/**
* Prüfen ob die angegebenen Zahlen dem Satz des Pythagoras entsprechen.
* @param a Die erste Zahl (a).
* @param b Die zweite Zahl (b).
* @param c Das Ergebnis (c).
* @return Status ob die angegebenen Zahlen dem Satz des Pythagoras entsprechen.
*/
public static boolean check(int a, int b, int c) {
return (a*a + b*b == c*c) ? true : false;
}
}

View File

@ -0,0 +1,30 @@
package VL03.Aufgabe03;
/**
* Vorlesung 3 / Aufgabe 3
*
* @author Sebastian Brosch
*/
public class Aufgabe03 {
public static void main(String[] args) {
int a = 3;
int b = 4;
int c = 5;
System.out.printf("a: %d, b: %d, c: %d\n", a, b, c);
System.out.println("Werte entsprechen dem Satz des Pythagoras: " + (check(a, b, c) ? "Ja" : "Nein"));
}
/**
* Method to check three numbers against the pythagorean theorem.
*
* @param a The first number (a in formula).
* @param b The second number (b in formula).
* @param c The result of the theorem (c in formula).
* @return The state whether the three numbers are matching the pythagorean
* theorem.
*/
public static boolean check(int a, int b, int c) {
return (a * a + b * b == c * c) ? true : false;
}
}