Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Objects;
- import java.util.Scanner;
- //import java.util.
- public class Main {
- public static void main(String[] args) {
- start:
- //1 naujas dalykas - break su label
- {
- double no1 = 0;
- double no2 = 0;
- double result;
- String[] symbols = {"*", "/", "+", "-"}; //2 naujas dalykas String array
- char sym;
- String yesno;
- System.out.println("Incomplete calculator");
- System.out.println("Enter the first number");
- Scanner input1 = new Scanner(System.in);
- no1 = input1.nextDouble();
- System.out.println("Enter the second number");
- Scanner input2 = new Scanner(System.in);
- no2 = input2.nextDouble();
- System.out.println("Enter what operation you want to do (+; -; *; /)");
- Scanner input3 = new Scanner(System.in);
- sym = input3.next().charAt(0);
- if (sym.equals(symbols)) {
- System.out.println("Illegal operation");
- break start;
- } else
- if (no2 == 0) {
- break start;
- } else if (Objects.equals(sym, "+")) {
- result = no1 + no2;
- System.out.println(result);
- System.out.println("Do you want to keep calculating?");
- Scanner input4 = new Scanner(System.in);
- yesno = input4.nextLine();
- if (yesno == "yes") {
- break start;
- } else ;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment