SHARE
TWEET

MAin.java

a guest Jun 20th, 2019 61 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package pckg.me.bxdev;
  2.  
  3. import java.util.Scanner;
  4.  
  5. public class MAin {
  6.     public static Scanner scanner = new Scanner(System.in);
  7.  
  8.     public static void main(String[] args) {
  9.         while(on) {
  10.             rechnung();
  11.         }
  12.     }
  13.    
  14.     private static boolean on = true;
  15.    
  16.     private static void rechnung() {
  17.  
  18.         System.out.println("Gib die erste Zahl ein");
  19.         String s = scanner.next();
  20.         System.out.println("Gib bitte dein Rechenzeichen an");
  21.         String rz = scanner.next();
  22.         System.out.println("Gib die zweite Zahl ein");
  23.         String s2 = scanner.next();
  24.         if(rz.equals("/")) {
  25.             div(Integer.parseInt(s),Integer.parseInt(s2));
  26.         }else if(rz.equals("*")) {
  27.             mul(Integer.parseInt(s),Integer.parseInt(s2));
  28.         }else if(rz.equals("-")) {
  29.             sub(Integer.parseInt(s),Integer.parseInt(s2));
  30.         }else if(rz.equals("+")) {
  31.             add(Integer.parseInt(s),Integer.parseInt(s2));
  32.         }else {
  33.             System.out.println(rz + " ist kein g├╝ltiges Rechenzeichen");
  34.         }
  35.         System.out.println("Rechner verlassen?(j/n)");
  36.         String s3 = scanner.next();
  37.         if(s3.equalsIgnoreCase("j")) {
  38.             on = false;
  39.         }  
  40.     }
  41.  
  42.     private static void add(double i, double j) {
  43.         double sol = i + j;
  44.         System.out.println(sol);
  45.     }
  46.    
  47.     private static void sub(double i, double j) {
  48.         double sol = i - j;
  49.         System.out.println(sol);
  50.     }
  51.  
  52.     private static void mul(double i, double j) {
  53.         double sol = i * j;
  54.         System.out.println(sol);
  55.     }
  56.  
  57.     private static void div(double i, double j) {
  58.         double sol = i / j;
  59.         System.out.println(sol);
  60.     }
  61. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top