Advertisement
Guest User

Test java bbw würznurg

a guest
Sep 26th, 2018
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.53 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class TrialandError {
  4.     public static void main(String[] args) {
  5.    
  6.    
  7.    
  8.     boolean nochmal = true;
  9.     while (nochmal) {
  10.         double zahl1, zahl2, Summe;
  11.         String operation;
  12.  
  13.         Scanner sc1 = new Scanner(System.in);
  14.        
  15.        
  16.         System.out.print("Geben Sie eine Zahl ein, mit der Sie rechnen möchten: ");
  17.         zahl1 = sc1.nextDouble();
  18.         System.out.print("Geben Sie eine Zahl ein, mit der Sie rechnen möchten: ");
  19.         zahl2 = sc1.nextDouble();
  20.         Scanner op = new Scanner (System.in);
  21.  
  22.     System.out.println("Bitte geben Sie das Rechenzeichen ein");
  23.     operation = op.next();
  24.  
  25.     if (operation.equals("+"))
  26.     {
  27.         System.out.println("Ihre Antwort ist "+(zahl1 + zahl2));
  28.     }
  29.     else if (operation.equals("-"))
  30.     {
  31.         System.out.println("Ihre Antwort ist "+(zahl1 - zahl2));
  32.     }      
  33.     else if (operation.equals("*"))
  34.     {
  35.         System.out.println("Ihre Antwort ist "+(zahl1 * zahl2));
  36.     }  
  37.     else if (operation.equals("/"))
  38.     {
  39.         System.out.println("Ihre Antwort ist "+(zahl1 / zahl2));
  40.     }    
  41.     else if (operation.equals("sqrt"))
  42.        
  43.     {
  44.         System.out.println("Ihre Antwort ist "+(Math.sqrt(zahl1)));    
  45.     }      
  46.        
  47.    
  48.    
  49.         Scanner scan2=new Scanner(System.in);
  50.         System.out.println("Nochmal rechnen? [J/N]");
  51.         String jaNein = scan2.next();
  52.         nochmal = jaNein.equalsIgnoreCase("j");
  53.      
  54.        
  55.    
  56.    
  57.    } }
  58. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement