Untitled

mail@pastecode.io avatar
unknown
java
2 years ago
3.0 kB
5
Indexable
Never
package com.ACT5B_Mayor_2;

import com.sun.scenario.effect.impl.sw.sse.SSEBlend_SRC_OUTPeer;

import java.util.Scanner;

public class ACT5B_Mayor_2 {

    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        // Declaring variable
        int num1, num2;
        char operator;
        int ans;
        //choices
        System.out.print("Arithmetic Operators\n* Addition \"+\"\n* Subtraction  \"-\"\n* Multiplication  \"*\"\n* Division  \"/\"\n* Modulus  \"%\"\n* Increment  \">\"\n* Decrement  \"<\"");
        // Inputting

        System.out.print("\nChoose operator to be use (eg. *): ");
        operator = scan.next().charAt(0);

        if (operator == '>') {
            System.out.print("Enter the value: ");
            num1 = scan.nextInt();
            ans = ++num1;
            System.out.println(ans);
        } else if (operator == '<') {
            System.out.print("Enter the value: ");
            num1 = scan.nextInt();
            ans = --num1;
            System.out.println(ans);
        } else {

            switch (operator) {
                case '+':
                    System.out.print("Enter first value: ");
                    num1 = scan.nextInt();
                    System.out.print("Enter second value: ");
                    num2 = scan.nextInt();
                    ans = num1 + num2;
                    System.out.println(ans);
                    break;
                case '-':
                    System.out.print("Enter first value: ");
                    num1 = scan.nextInt();
                    System.out.print("Enter second value: ");
                    num2 = scan.nextInt();
                    ans = num1 - num2;
                    System.out.println(ans);
                    break;
                case '*':
                    System.out.print("Enter first value: ");
                    num1 = scan.nextInt();
                    System.out.print("Enter second value: ");
                    num2 = scan.nextInt();
                    ans = num1 * num2;
                    System.out.println(ans);
                    break;
                case '/':
                    System.out.print("Enter first value: ");
                    num1 = scan.nextInt();
                    System.out.print("Enter second value: ");
                    num2 = scan.nextInt();
                    ans = num1 / num2;
                    System.out.println(ans);
                    break;
                case '%':
                    System.out.print("Enter first value: ");
                    num1 = scan.nextInt();
                    System.out.print("Enter second value: ");
                    num2 = scan.nextInt();
                    ans = num1 % num2;
                    System.out.println(ans);
                    break;
                default:
                    System.out.println("Please use proper operator.");
            }

        }

    }
}