Hallo
In diesem Beispiel soll ich prüfen ob a, b, c und d drei gleiche Werte enthalten
In Zeile 14 seht ihr dazu meinen ersten Versuch. Kann man das anders programmieren also in einer vereinfachten Form?
Danke!
public class Uebung {
public static void main(String[] args) {
Out.print("enter the first number: ");
int a = In.readInt();
Out.print("enter the second number: ");
int b = In.readInt();
Out.print("enter the third number: ");
int c = In.readInt();
Out.print("enter the fourth number: ");
int d = In.readInt();
if (a==b && b==c && c==d) {
Out.print("Alle Werte sind gleich.");
} else if ((a==b && b==c) || (b==c && c==d) || (a==b && b==d) || (a==c && c==d)) {
Out.print("Drei Werte sind gleich.");
} else if (
}
}
Der Code ist noch nicht fertig
In diesem Beispiel soll ich prüfen ob a, b, c und d drei gleiche Werte enthalten
In Zeile 14 seht ihr dazu meinen ersten Versuch. Kann man das anders programmieren also in einer vereinfachten Form?
Danke!

public class Uebung {
public static void main(String[] args) {
Out.print("enter the first number: ");
int a = In.readInt();
Out.print("enter the second number: ");
int b = In.readInt();
Out.print("enter the third number: ");
int c = In.readInt();
Out.print("enter the fourth number: ");
int d = In.readInt();
if (a==b && b==c && c==d) {
Out.print("Alle Werte sind gleich.");
} else if ((a==b && b==c) || (b==c && c==d) || (a==b && b==d) || (a==c && c==d)) {
Out.print("Drei Werte sind gleich.");
} else if (
}
}
Der Code ist noch nicht fertig
Zuletzt bearbeitet: