Advertisement
winone1208

Java zad2

Mar 19th, 2021
630
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.32 KB | None | 0 0
  1. package pl.patrykk;
  2.  
  3. import java.util.Scanner;
  4.  
  5. public class Main {
  6.  
  7.     public static void main(String[] args) {
  8.  
  9.         Scanner scanner = new Scanner(System.in);
  10.         System.out.println("KALKULATOR\n");
  11.         System.out.println("Podaj liczbę:");
  12.         double liczba1 = scanner.nextDouble();
  13.  
  14.         scanner.nextLine();
  15.         System.out.println("Podaj znak +, -, *, /:");
  16.         String symbol = scanner.nextLine();
  17.  
  18.         System.out.println("Podaj liczbę:");
  19.         double liczba2 = scanner.nextDouble();
  20.  
  21.         if (liczba2 == 0 && symbol.equals("/")) {
  22.  
  23.             System.out.println("Nie dziel przez ZERO");
  24.  
  25.         } else {
  26.  
  27.             switch (symbol) {
  28.                 case "+":
  29.                     System.out.println("Wynik: " + (liczba1 + liczba2));
  30.                     break;
  31.                 case "-":
  32.                     System.out.println("Wynik: " + (liczba1 - liczba2));
  33.                     break;
  34.                 case "*":
  35.                     System.out.println("Wynik: " + (liczba1 * liczba2));
  36.                     break;
  37.                 case "/":
  38.                     System.out.println("Wynik: " + (liczba1 / liczba2));
  39.                     break;
  40.  
  41.                 default:
  42.                     System.out.println("Błąd");
  43.             }
  44.  
  45.         }
  46.  
  47.  
  48.  
  49.  
  50.  
  51.  
  52.  
  53.  
  54.     }
  55. }
  56.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement