Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package rechnen3;
- import javax.swing.*;
- public class Mathe4
- {
- public static void main(String[] args)
- {
- float Ergebnis = 0;
- String Text = "Ergebnis ist ";
- try
- {
- String Eingabe1 = JOptionPane.showInputDialog ("Berdie gib eine Zahl ein:");
- String Eingabe2 = JOptionPane.showInputDialog ("Berdie, bitte noch eine Zahl:");
- String Operator = JOptionPane.showInputDialog("Jetzt noch die Rechnungsart, also ein Operator wie du sicherlich weißt:");
- float Zahl1 = Float.parseFloat(Eingabe1);
- float Zahl2 = Float.parseFloat(Eingabe2);
- if (Operator.equals("+"))
- Ergebnis = Zahl1 + Zahl2;
- if (Operator.equals("-"))
- Ergebnis = Zahl1 - Zahl2;
- if (Operator.equals("*"))
- Ergebnis = Zahl1 * Zahl2;
- if (Operator.equals("/"))
- if (Zahl2 != 0) Ergebnis = Zahl1 / Zahl2;
- else Text = "Division durch null ";
- }
- catch (Exception x)
- {
- Text = "Versteh ich nicht! ";
- }
- if (Text.equals("Ergebnis ist "))
- Text = Text + Ergebnis;
- JOptionPane.showMessageDialog (null, Text);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement