while (antwort== "j")
{
System.exit(0);
}
while (antwort == "n"){
}
while (antwort != "j"){
System.out.println("Falsche Eingabe!");
}
while (antwort != "n"){
System.out.println("Falsche Eingabe!");
}
}
while (antwort != "n"){
System.out.println("Falsche Eingabe!");
}
while (antwort == "n"){
}
while (antwort != "n" && antwort !="j"){
}
this.antwort="wert";
if(antwort = n){
wiederhole methode
}
public class MPGTester2 {
private double tanfangsbestand = 0.0;
private double tachometerstand;
private double anzgallone;
private double meilen;
private String antwort;
public MPGTester2(double tanfangsbestand, double tachometerstand, double anzgallone, double meilen, String antwort){
}
public static void main (String[] args){
double tanfangsbestand = 0.0;
double tachometerstand;
double anzgallone;
Scanner scan = new Scanner(System.in);
System.out.println("Neues Auto - Tachometer-Anfangsstand: " + tanfangsbestand);
System.out.println("Aktuellen Tachostand eingeben:");
tachometerstand = scan.nextDouble();
System.out.println("Anzahl der Gallonen für die Tankfüllung:");
anzgallone = scan.nextDouble();
MPGTester2 t = new MPGTester2();
t.auftanken(tachometerstand, anzgallone);
}
void auftanken(double tachometerstand, double anzgallone){
double m = tachometerstand / anzgallone;
System.out.println("Meilen pro Gallone: " + m);
if (m < 15.0){
System.out.println("Autotyp: Sparauto!");
}
else if (m >30.0){
System.out.println("Autotyp: Benzinschwein!");
}
Strings vergleicht man mit [c]equals()[/c], nicht mit [c]==[/c]!
@achillesat: mit nur einem [c]=[/c], noch mehr Kacke
while (antwort.equals("j"))
{
System.exit(0);
}
while (antwort.equals("n")){
}
while (antwort != "j" && antwort != "n"){
System.out.println("Falsche Eingabe!");
}
!
if(!antwort.equals("j") && !antwort.equals("n")) {
System.out.println("Falsche Eingabe!");
}
String input = null;
while(!"n".equals((input = readInput())){
if("y".equals(input)){
// mach was mit y
} else if("abc".equals(input)){
// tu was anderes
}
}
public class MPGTester2 {
private double tanfangsbestand = 0.0;
private double tachometerstand;
private double anzgallone;
private double meilen;
private String antwort;
public MPGTester2(double tanfangsbestand, double tachometerstand, double anzgallone, double meilen, String antwort) {
}
public static void main(String[] args) {
double tanfangsbestand = 0.0;
double tachometerstand;
double anzgallone;
String antwort = "";
while (!antwort.equals("j")) {
Scanner scan = new Scanner(System.in);
System.out.println("Neues Auto - Tachometer-Anfangsstand: " + tanfangsbestand);
System.out.println("Aktuellen Tachostand eingeben:");
tachometerstand = scan.nextDouble();
System.out.println("Anzahl der Gallonen für die Tankfüllung:");
anzgallone = scan.nextDouble();
double m = tachometerstand / anzgallone;
System.out.println("Meilen pro Gallone: " + m);
if (m < 15.0) {
System.out.println("Autotyp: Benzinschwein!");
} else if (m > 30.0) {
System.out.println("Autotyp: Sparauto!");
}
System.out.println("Programm beenden? [j] [n]");
antwort = scan.next();
while (!antwort.equals("j") && !antwort.equals("n")) {
System.out.println("Falsche Eingabe! Geben Sie es nochmal ein!");
antwort = scan.next();
}
}
}
}