Facebook
From Sweet Flamingo, 6 Years ago, written in Java.
This paste is a reply to Untitled from Idiotic Mockingbird - view diff
Embed
Download Paste or View Raw
Hits: 372
  1. package odczytywanie;
  2.  
  3. import java.util.Scanner;
  4.  
  5. public class Odczytywanie {
  6.  
  7.     public static void main(String[] args) {
  8.         double a;
  9.         double b;
  10.         Scanner podaj = new Scanner(System.in);
  11.         Scanner wybor = new Scanner(System.in);
  12.         kalkulator dzialania = new kalkulator();
  13.         System.out.println("Co chcesz zrobić? 1. Dodawanie 2. Odejmowanie");
  14.         int wybor_1 = wybor.nextInt();
  15.         while (wybor_1 >= 3) {
  16.             if (wybor_1 >= 3) {
  17.                 System.out.println("Nie ma takiej opcji, wybierz ponownie");
  18.  
  19.                 System.out.println("Co chcesz zrobić? 1. Dodawanie 2. Odejmowanie");
  20.                 wybor_1 = wybor.nextInt();
  21.  
  22.             } else {
  23.  
  24.                 switch (wybor_1) {
  25.                     case 1:
  26.                         System.out.println("Podaj pierwsza liczbę:");
  27.                         a = podaj.nextInt();
  28.                         System.out.println("Podaj drugą liczbę");
  29.                         b = podaj.nextInt();
  30.                         System.out.println("Wynik to: " + dzialania.dodaj(a, b));
  31.                         break;
  32.                     case 2:
  33.                         System.out.println("Podaj pierwsza liczbę:");
  34.                         a = podaj.nextDouble();
  35.                         System.out.println("Podaj drugą liczbę");
  36.                         b = podaj.nextDouble();
  37.                         System.out.println("Wynik to: " + dzialania.odejmij(a, b));
  38.                         break;
  39.  
  40.                 }
  41.  
  42.             }
  43.         }
  44.         switch (wybor_1) {
  45.             case 1:
  46.                 System.out.println("Podaj pierwsza liczbę:");
  47.                 a = podaj.nextInt();
  48.                 System.out.println("Podaj drugą liczbę");
  49.                 b = podaj.nextInt();
  50.                 System.out.println("Wynik to: " + dzialania.dodaj(a, b));
  51.                 break;
  52.             case 2:
  53.                 System.out.println("Podaj pierwsza liczbę:");
  54.                 a = podaj.nextDouble();
  55.                 System.out.println("Podaj drugą liczbę");
  56.                 b = podaj.nextDouble();
  57.                 System.out.println("Wynik to: " + dzialania.odejmij(a, b));
  58.                 break;
  59.  
  60.         }
  61.     }
  62.  
  63.     public static class kalkulator {
  64.  
  65.         public double dodaj(double a, double b) {
  66.             return a + b;
  67.         }
  68.  
  69.         public double odejmij(double a, double b) {
  70.             return a - b;
  71.         }
  72.     }
  73. }
  74.