Simple Calculator project using java

This calculator project using java:

simple calculator

The code is given bellow:



import java.util.Scanner;

public class Main {
static Scanner myScanner= new Scanner(System.in);
static String[] calculator={"add","sub","div","mul"};

public static void main(String[] args) {

System.out.println("Welcome to Simple calculator project!!");
System.out.println("What you want to do?/n Ans:");
System.out.println("Enter "+ calculator[0] + " for Addition, " + calculator[1] + " for Substraction, "+ calculator[2] +" for Division and "+ calculator[3] +" for Multiplication");
String choice = myScanner.nextLine();

System.out.print("Enter First Number:");

int num1 = myScanner.nextInt();


System.out.print("Enter Second Number:");

int num2= myScanner.nextInt();

if (calculator[0].toLowerCase().endsWith(choice.toLowerCase())) {
System.out.println("You want to "+ calculator[0] +" Numbers");
add(num1, num2);

}
else if (calculator[1].toLowerCase().equals(choice.toLowerCase())) {
System.out.println("You want to "+ calculator[1] +" Numbers");
sub(num1, num2);
}else if (calculator[2].toLowerCase().equals(choice.toLowerCase())) {
System.out.println("You want to "+ calculator[2]+ " Numbers");
div(num1, num2);
}else if (calculator[3].toLowerCase().equals(choice.toLowerCase())) {
System.out.println("You want to "+ calculator[2]+ " Numbers");
mul(num1, num2); }
else {
System.out.println("Wrong Choice!!");

}

}

private static void add(int num1, int num2) {

int result = num1+num2;
showResult(result);

}
private static void sub(int num1, int num2) {

int result = num1-num2;
showResult(result);

}
private static void div(int num1, int num2) {

int result = num1/num2;
showResult(result);

}
private static void mul(int num1, int num2) {

int result = num1*num2;
showResult(result);

}
static void showResult(int result){
System.out.println("Result is: "+result);
System.out.println("\n=======Thank you for visiting 'Programming Help'=========");

}
}



Sample Output:
simple calculator



Happy Coding..

Simple Calculator project using java. Use java programming language to implement calculator. Simple Calculator project using java code.