mercredi 20 mai 2015

If-anweisung per ja eingabe.

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 Code:

  1. import javax.swing.JOptionPane;
  2.  
  3.  
  4.  
  5. public class If {
  6.  
  7.  
  8. public static void main(String[] args) {
  9. // TODO Auto-generated method stub
  10.  
  11. String eingabe;
  12. char c;
  13.  
  14. eingabe = JOptionPane.showInputDialog("ja oder nein");
  15. c = eingabe.charAt(0);
  16.  
  17. if (c == 'j' + 'a') {
  18. System.out.println("Jawollo");
  19. }
  20.  
  21. else {
  22. System.out.println("falsche Antwort");
  23. {
  24. }
  25.  
  26.  
  27. }
  28. }
  29. }


Gebe ich nun in der if anweisung c == ´a´ ein, so funktioniert das Programm einwandfrei.

Java Code:

  1. if (c == 'a') { System.out.println("Jawollo");
  2. }


Hat jemand eine Idee wie ich dieses Problem lösen kann?
Miniaturansichten angehängter Grafiken
Klicken Sie auf die Grafik für eine größere Ansicht  Name: ja.jpg  Hits: -  Größe: 37,5 KB  ID: 7790  


If-anweisung per ja eingabe.

0 commentaires:

Enregistrer un commentaire