Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package javaapplication12;
- import java.util.InputMismatchException;
- import java.util.Scanner;
- //klasa opisujaca wyjatek dzielenia przez zero
- class DzieleniePrzezZero extends Exception {
- }
- public class Kalkulator {
- public static void main(String[] args) throws DzieleniePrzezZero {
- Scanner skaner = new Scanner(System.in);
- System.out.println("-== Kalkulator ==-");
- System.out.println("Dzielenie");
- System.out.print("Dzielna: ");
- double a = 0;
- try {
- a = skaner.nextDouble();
- } catch(InputMismatchException ex) {
- System.out.println("BLAD: Niepoprawne dane wejsciowe: " + ex);
- return;
- //ex.printStackTrace();
- }
- System.out.print("Dzielnik: ");
- double b = 0;
- try {
- b = skaner.nextDouble();
- } catch(InputMismatchException ex) {
- System.out.println("BLAD: Niepoprawne dane wejsciowe: " + ex);
- return;
- }
- if(b==0) {
- throw new DzieleniePrzezZero();
- }
- double c = a/b;
- System.out.println("Iloraz: " + c);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement