Ich möchte per Tastatur ja eingeben damit die if anweisung Jawollo herausgibt.
Wenn ich also ja eingebe gibt mir das Programm falsche antwort heraus.
[JAVA]import javax.swing.JOptionPane;
public class If {
public static void main(String[] args) {
// TODO Auto-generated method stub
String eingabe;
char c;
eingabe = JOptionPane.showInputDialog("ja oder nein");
c = eingabe.charAt(0);
if (c == 'j' + 'a') {
System.out.println("Jawollo");
}
else {
System.out.println("falsche Antwort");
{
}
}
}
}[/code]
Gebe ich nun in der if anweisung c == ´a´ ein, so funktioniert das Programm einwandfrei.
[JAVA] if (c == 'a') { System.out.println("Jawollo");
}
[/code]
Hat jemand eine Idee wie ich dieses Problem lösen kann?
Wenn ich also ja eingebe gibt mir das Programm falsche antwort heraus.
[JAVA]import javax.swing.JOptionPane;
public class If {
public static void main(String[] args) {
// TODO Auto-generated method stub
String eingabe;
char c;
eingabe = JOptionPane.showInputDialog("ja oder nein");
c = eingabe.charAt(0);
if (c == 'j' + 'a') {
System.out.println("Jawollo");
}
else {
System.out.println("falsche Antwort");
{
}
}
}
}[/code]
Gebe ich nun in der if anweisung c == ´a´ ein, so funktioniert das Programm einwandfrei.
[JAVA] if (c == 'a') { System.out.println("Jawollo");
}
[/code]
Hat jemand eine Idee wie ich dieses Problem lösen kann?
Anhänge
Zuletzt bearbeitet: