MariusTheMaster

1Lab

Sep 27th, 2023
199
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.60 KB | None | 0 0
  1. import java.util.Objects;
  2. import java.util.Scanner;
  3. //import java.util.
  4.  
  5. public class Main {
  6.     public static void main(String[] args) {
  7.         start:
  8.         //1 naujas dalykas - break su label
  9.         {
  10.             double no1 = 0;
  11.             double no2 = 0;
  12.             double result;
  13.             String[] symbols = {"*", "/", "+", "-"}; //2 naujas dalykas String array
  14.             char sym;
  15.             String yesno;
  16.  
  17.             System.out.println("Incomplete calculator");
  18.             System.out.println("Enter the first number");
  19.             Scanner input1 = new Scanner(System.in);
  20.             no1 = input1.nextDouble();
  21.             System.out.println("Enter the second number");
  22.             Scanner input2 = new Scanner(System.in);
  23.             no2 = input2.nextDouble();
  24.             System.out.println("Enter what operation you want to do (+; -; *; /)");
  25.             Scanner input3 = new Scanner(System.in);
  26.             sym = input3.next().charAt(0);
  27.  
  28.             if (sym.equals(symbols)) {
  29.                 System.out.println("Illegal operation");
  30.                 break start;
  31.             } else
  32.             if (no2 == 0) {
  33.                 break start;
  34.             } else if (Objects.equals(sym, "+")) {
  35.                 result = no1 + no2;
  36.                 System.out.println(result);
  37.  
  38.                 System.out.println("Do you want to keep calculating?");
  39.                 Scanner input4 = new Scanner(System.in);
  40.                 yesno = input4.nextLine();
  41.                 if (yesno == "yes") {
  42.                     break start;
  43.                 } else ;
  44.  
  45.             }
  46.         }
  47.     }
  48. }
Advertisement
Add Comment
Please, Sign In to add comment