Advertisement
Guest User

Untitled

a guest
May 22nd, 2017
50
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.07 KB | None | 0 0
  1. package rechnen3;
  2.  
  3. import javax.swing.*;
  4.  
  5. public class Mathe4
  6. {
  7.  
  8. public static void main(String[] args)
  9. {
  10. float Ergebnis = 0;
  11. String Text = "Ergebnis ist ";
  12.  
  13. try
  14. {
  15. String Eingabe1 = JOptionPane.showInputDialog ("Berdie gib eine Zahl ein:");
  16. String Eingabe2 = JOptionPane.showInputDialog ("Berdie, bitte noch eine Zahl:");
  17. String Operator = JOptionPane.showInputDialog("Jetzt noch die Rechnungsart, also ein Operator wie du sicherlich weißt:");
  18.  
  19. float Zahl1 = Float.parseFloat(Eingabe1);
  20. float Zahl2 = Float.parseFloat(Eingabe2);
  21.  
  22. if (Operator.equals("+"))
  23. Ergebnis = Zahl1 + Zahl2;
  24. if (Operator.equals("-"))
  25. Ergebnis = Zahl1 - Zahl2;
  26. if (Operator.equals("*"))
  27. Ergebnis = Zahl1 * Zahl2;
  28. if (Operator.equals("/"))
  29. if (Zahl2 != 0) Ergebnis = Zahl1 / Zahl2;
  30. else Text = "Division durch null ";
  31.  
  32. }
  33. catch (Exception x)
  34. {
  35. Text = "Versteh ich nicht! ";
  36. }
  37. if (Text.equals("Ergebnis ist "))
  38. Text = Text + Ergebnis;
  39.  
  40. JOptionPane.showMessageDialog (null, Text);
  41.  
  42. }
  43.  
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement