Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Kalkulator {
- public static void main(String[] args) {
- boolean e=false;
- double w, a=1, b=1, c=1;
- int s=0;
- String o="";
- String x="";
- String y="";
- Scanner scan = new Scanner(System.in);
- // scan.reset();
- do{
- do
- {try {e=false;
- System.out.println("Jakie działanie chcesz wykonać?(1-dodawanie, 2-odejmowanie, 3-mnożenie, 4-dzielenie)");
- o = scan.nextLine();
- c = Double.parseDouble(o);}
- catch(NumberFormatException ee) {System.err.println("Błąd danych wejściowych"); e=true;}
- } while (e);
- do
- {try {e=false;
- System.out.println("Podaj pierwszą liczbę");
- x = scan.nextLine();
- b = Double.parseDouble(x);}
- catch(NumberFormatException ee) {System.err.println("Błąd danych wejściowych"); e=true;}
- } while (e);
- do
- {try {e=false;
- System.out.println("Podaj drugą liczbę");
- y = scan.nextLine();
- a = Double.parseDouble(y);}
- catch(NumberFormatException ee) {System.err.println("Błąd danych wejściowych"); e=true;}
- } while (e);
- if(c==1){
- w=b+a;
- System.out.println(w);}
- else if(c==2){
- w=b-a;
- System.out.println(w);}
- else if(c==3){
- w=b*a;
- System.out.println(w);}
- else if(c==4){
- w=b/a;
- System.out.println(w);}
- System.out.println("Czy chcesz policzyć coś jeszcze?(1-tak, nie-dowolna liczba)");
- s = scan.nextInt();
- }while (s==1);
- }}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement