Search
 
SCRIPT & CODE EXAMPLE
 

JAVA

Calculator repeat

import java.util.Scanner;

public class Adv_calc {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int option;
        double num1, num2, result;
        result = 0;
        do {
            System.out.println("Welcome to The Calculator app");
            System.out.println("Please Choose an option");
            System.out.println("1) Add");
            System.out.println("2) Subtract");
            System.out.println("3) Multiply");
            System.out.println("4) Continue");
            System.out.println("5) Exit");
            System.out.print("Option :: ");
            option = sc.nextInt();
            switch (option) {
            case 1: {
                System.out.println("Addition Calculator");
                System.out.print("Kindly Enter the FIRST Number :: ");
                num1 = sc.nextDouble();
                System.out.print("Kindly Enter the SECOND Number :: ");
                num2 = sc.nextDouble();
                result = num1 + num2;
                System.out.print("The Result is :: ");
                System.out.println(result);
                break;
            }
            case 2: {
                System.out.println("Subtraction Calculator");
                System.out.print("Kindly Enter the FIRST Number :: ");
                num1 = sc.nextDouble();
                System.out.print("Kindly Enter the SECOND Number :: ");
                num2 = sc.nextDouble();
                result = num1 - num2;
                System.out.print("The Result is :: ");
                System.out.println(result);
                break;
            }
            case 3: {
                System.out.println("Multiplication Calculator");
                System.out.print("Kindly Enter the FIRST Number :: ");
                num1 = sc.nextDouble();
                System.out.print("Kindly Enter the SECOND Number :: ");
                num2 = sc.nextDouble();
                result = num1 * num2;
                System.out.print("The Result is :: ");
                System.out.println(result);
                break;
            }
            case 4: {
                System.out.println("Please Choose an option");
                System.out.println("1) Add");
                System.out.println("2) Subtract");
                System.out.println("3) Multiply");
                System.out.print("Option :: ");
                option = sc.nextInt();
                switch (option) {
                case 1: {
                    System.out.println("Addition Calculator");
                    System.out.print("Kindly Enter the SECOND Number :: ");
                    num2 = sc.nextDouble();
                    result = result + num2;
                    System.out.print("The Result is :: ");
                    System.out.println(result);
                    break;
                }
                case 2: {
                    System.out.println("Subtraction Calculator");
                    System.out.print("Kindly Enter the SECOND Number :: ");
                    num2 = sc.nextDouble();
                    result = result - num2;
                    System.out.print("The Result is :: ");
                    System.out.println(result);
                    break;
                }
                case 3: {
                    System.out.println("Multiplication Calculator");
                    System.out.print("Kindly Enter the SECOND Number :: ");
                    num2 = sc.nextDouble();
                    result = result * num2;
                    System.out.print("The Result is :: ");
                    System.out.println(result);
                    break;
                }
                }
                break;
            }
            case 5: {
                System.out.println("Thank you for using my program :: ");
                System.out.println("Program will now exit ");
                System.exit(0);
            }
            }
        } while (option != 5);
    }

}
Comment

PREVIOUS NEXT
Code Example
Java :: add external JARs to java vscode 
Java :: Java create an object of the non-static class Reptile 
Java :: java %2C 
Java :: preparestatement method in java 
Java :: java convert 2d array to 1d stream 
Java :: what is difference between constant and final in java 
Java :: trémaux’ methode 
Java :: sha1 
Java :: how to write a perfect shuffle method in java 
Java :: java longest paldrome 
Java :: Java Boolean Literals 
Java :: find if element is powers of 2 
Java :: interview questions on ds and algo 
Java :: @exceptionhandler spring boot annotation not found 
Java :: oxygen cylinder management program in java 
Java :: poo pledin 3.0 
Java :: java Color on Enum call 
Java :: java program on stack for beginners 
Java :: resources/android/xml/network_security_config.xml 
Java :: java take inpt into arraylist 
Java :: reader java 
Java :: why fields should be final in immutable class? 
Java :: java load config file 
Java :: Java Insert Elements to EnumSet 
Java :: Array pocket in java 
Java :: how to convert string to int android studio kotlin 
Java :: Write a java program to print the ip address 
Java :: gif to blob java 
Java :: java ordenar numeros ascendente 
Java :: control statements 
ADD CONTENT
Topic
Content
Source link
Name
8+1 =