Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class TrialandError {
- public static void main(String[] args) {
- boolean nochmal = true;
- while (nochmal) {
- double zahl1, zahl2, Summe;
- String operation;
- Scanner sc1 = new Scanner(System.in);
- System.out.print("Geben Sie eine Zahl ein, mit der Sie rechnen möchten: ");
- zahl1 = sc1.nextDouble();
- System.out.print("Geben Sie eine Zahl ein, mit der Sie rechnen möchten: ");
- zahl2 = sc1.nextDouble();
- Scanner op = new Scanner (System.in);
- System.out.println("Bitte geben Sie das Rechenzeichen ein");
- operation = op.next();
- if (operation.equals("+"))
- {
- System.out.println("Ihre Antwort ist "+(zahl1 + zahl2));
- }
- else if (operation.equals("-"))
- {
- System.out.println("Ihre Antwort ist "+(zahl1 - zahl2));
- }
- else if (operation.equals("*"))
- {
- System.out.println("Ihre Antwort ist "+(zahl1 * zahl2));
- }
- else if (operation.equals("/"))
- {
- System.out.println("Ihre Antwort ist "+(zahl1 / zahl2));
- }
- else if (operation.equals("sqrt"))
- {
- System.out.println("Ihre Antwort ist "+(Math.sqrt(zahl1)));
- }
- Scanner scan2=new Scanner(System.in);
- System.out.println("Nochmal rechnen? [J/N]");
- String jaNein = scan2.next();
- nochmal = jaNein.equalsIgnoreCase("j");
- } }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement