Advertisement
leniuch

kalkulator

Feb 25th, 2020
156
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.58 KB | None | 0 0
  1. public class Kalkulator {
  2.  
  3.    
  4.     public static void main(String[] args) {
  5.         boolean e=false;
  6.         double w, a=1, b=1, c=1;
  7.         int s=0;
  8.         String o="";
  9.         String x="";
  10.         String y="";
  11.         Scanner scan = new Scanner(System.in);
  12.        
  13.       // scan.reset();
  14. do{      
  15. do
  16. {try {e=false;
  17.     System.out.println("Jakie działanie chcesz wykonać?(1-dodawanie, 2-odejmowanie, 3-mnożenie, 4-dzielenie)");
  18.         o = scan.nextLine();
  19.         c = Double.parseDouble(o);}
  20.         catch(NumberFormatException ee) {System.err.println("Błąd danych wejściowych"); e=true;}
  21.             } while (e);
  22.        
  23.  
  24.      
  25.  do
  26. {try {e=false;
  27.     System.out.println("Podaj pierwszą liczbę");
  28.         x = scan.nextLine();
  29.         b = Double.parseDouble(x);}
  30.         catch(NumberFormatException ee) {System.err.println("Błąd danych wejściowych"); e=true;}
  31.             } while (e);
  32.  
  33.  
  34. do
  35. {try {e=false;
  36.     System.out.println("Podaj drugą liczbę");
  37.         y = scan.nextLine();
  38.         a = Double.parseDouble(y);}
  39.         catch(NumberFormatException ee) {System.err.println("Błąd danych wejściowych"); e=true;}
  40.             } while (e);
  41.  
  42.  
  43.    
  44.     if(c==1){
  45.     w=b+a;
  46.         System.out.println(w);}
  47.     else if(c==2){
  48.      w=b-a;
  49.         System.out.println(w);}
  50.     else if(c==3){
  51.      w=b*a;
  52.         System.out.println(w);}
  53.     else if(c==4){
  54.      w=b/a;
  55.         System.out.println(w);}
  56.    
  57.     System.out.println("Czy chcesz policzyć coś jeszcze?(1-tak, nie-dowolna liczba)");
  58.     s = scan.nextInt();
  59.    
  60.  }while (s==1);
  61. }}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement