Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package lab_01;
- import java.util.Scanner;
- import java.lang.Math;
- public class Klasa {
- public static void main(String[] args) {
- // TODO Auto-generated method stub
- String operacja = args[0];
- int liczba1, liczba2;
- liczba2 = 0;
- float wynik = 0;
- boolean poprawne = true;
- liczba1 = Integer.parseInt(args[1]);
- if(!operacja.equals("sqrt")) liczba2 = Integer.parseInt(args[2]);
- if (operacja.equals("+")) wynik = liczba1 + liczba2;
- else if(operacja.equals("-")) wynik = liczba1 - liczba2;
- else if(operacja.equals(".")) wynik = liczba1 * liczba2;
- else if(operacja.equals("/"))
- {
- if(liczba2 != 0) wynik = liczba1 / liczba2;
- else
- {
- System.out.println("Błąd dzielenia przez 0");
- poprawne = false;
- }
- }
- else if(operacja.equals("^")) wynik = (float) Math.pow(liczba1, liczba2);
- else if(operacja.equals("sqrt")) wynik = (float) Math.sqrt(liczba1);
- else if(operacja.equals("%")) wynik = liczba1 % liczba2;
- else
- {
- System.out.println("Podano nieprawidłową operację");
- poprawne = false;
- }
- if(poprawne)
- {
- System.out.println("Wynik operacji wynosi: ");
- System.out.println(wynik);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement