Aufgaben bis Nullstellen
parent
0abc96e4e1
commit
8a02fe0919
65
Übungen.java
65
Übungen.java
|
@ -51,12 +51,61 @@ public class Übungen
|
|||
Scanner sc = new Scanner(System.in);
|
||||
System.out.println (a*b);
|
||||
}
|
||||
//public static boolean Primzahlen5 (int n) {
|
||||
// Scanner sc = new Scanner(System.in);
|
||||
// boolean zahl = 1;
|
||||
//if (zahl = ){
|
||||
//}
|
||||
//return zahl;
|
||||
|
||||
public static boolean istPrim (int n) { //Primzahlen ja nein
|
||||
Scanner sc = new Scanner(System.in);
|
||||
boolean zahl = false;
|
||||
for (int i=2; i<n; i++){
|
||||
if (n % i== 0) { // % Rest --> wenn der Restwert von i = 0 ist ...
|
||||
zahl = false;
|
||||
break; // beendet die Schleife direkt ohne weiter zu gehen
|
||||
}
|
||||
else {
|
||||
zahl = true;
|
||||
}
|
||||
}
|
||||
return zahl;
|
||||
}
|
||||
|
||||
public static void istPrim2(){
|
||||
Scanner sc = new Scanner(System.in);
|
||||
int min = sc.nextInt();
|
||||
while (true) {
|
||||
if (istPrim(min)){
|
||||
int min2 = min + 2;
|
||||
if (istPrim(min2)){
|
||||
System.out.println(min + "und" + min2 + "sind Primzahl-Doubletten");
|
||||
break; // beendet die Schleife direkt
|
||||
}
|
||||
else {
|
||||
min = min + 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
public static void pythagoräischeTripel(){
|
||||
for (int a = 1; a <= 100; a++){
|
||||
for (int b = 1; b <= 100; b++){
|
||||
for (int c =1; c <= 100; c++) {
|
||||
if (c*c == a*a +b*b){
|
||||
System.out.println (a + " , " + b + " , " + c);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
public static void Nullstellen(){
|
||||
Scanner sc = new Scanner(System.in);
|
||||
float m = sc.nextInt();
|
||||
float c = sc.nextInt();
|
||||
if (c == 0 && m == 0) {
|
||||
System.out.println("unendlich viele Nullstellen");
|
||||
|
||||
}
|
||||
else if (m ==0){
|
||||
System.out.println("keine Nullstellen");
|
||||
|
||||
}
|
||||
|
||||
float x = (-c) /m;
|
||||
System.out.println("Nullstelle ist: x= " + x);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue