Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package kalkulator;
- import java.util.InputMismatchException;
- import java.util.Scanner;
- // klasa opisujaca wyjatek: dzielenie 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("Wykonuje dzielenie: ");
- System.out.println("Dzielna = ");
- double a = 0;
- double b = 0;
- double c = 0;
- try {
- a = skaner.nextDouble();
- } catch (InputMismatchException ex) {
- // ex.printStackTrace();
- System.out.println("Użytkowniku kochany podaj liczbe we właściwym formacie!");
- return;
- }
- System.out.println("Dzielnik = ");
- try {
- b = skaner.nextDouble();
- } catch (InputMismatchException ex) {
- // ex.printStackTrace();
- System.out.println("Użytkowniku kochany podaj liczbe we właściwym formacie!");
- return;
- }
- if (b == 0) {
- throw new DzieleniePrzezZero(); // "Dzielnik jest równy zero!"
- } else {
- c = a / b;
- }
- System.out.println("Iloczyn = " + c);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement