Create a scientific calculator using Java, Java Scientific Calculator, e.g logarithm, Factorial, etc.

  In this java tutorial, we will learn how to create a Java scientific calculator using basic java, which helps in to perform operations like Factorial, Square Root,logarithm, Factorial, etc.

There are some features of the Java Scientific Calculator

The following java scientific calculator will able to perform the following task:

  1. Addition(): To add one or more number.
  2. Subtraction(): subtract the numbers.
  3. Divide(): Divide the two numbers.
  4. Multiplcation(): multiplicatin of numbers.
  5. Sin Value(): Get the value in radians as well as the degree of Sin.
  6. Cos Value(): Get the value in radians as well as the degree of Cos.
  7. Tan Value(): Get the value in radians as well as the degree of Tan.
  8. Log Value(): Find the value of Log Using Math.log() funtion.
  9. Factorial(): Calculate the factorial of given number.
  10. Square Root(): Find the sequare root of numbers. e.g. √36 is 6.

Java Scientific Calculator Program

In the following program we uses a package called import java.util.*; The output of the program shown below:

																
/*;==========================================
; Title: create a Java scientific calculator
; Author: codenaive littleboy8506@  <admin@codenaive.com> <s.8506.a@gmail.com>
; Date:   13 Dec 2021
;==========================================*/
import java.util.*;
interface Defination
{   public void Add();
 public void Sub();
 public void Multi();
 public void SinValue();
    public void CosValue();
 public void TanValue();
 public void LogValue();
 public void Factorial();
 public void Swap();
 public void SquareRoot();
}
class Operation implements Defination 
{   public void Add()
 {   
  Scanner obj = new Scanner(System.in);
  int input,total=0;
  System.out.println("Enter The Range Of Number For Addition : ");
  try{
  input=obj.nextInt();
  
     int[] range=new int [input];
  for(int i=0;i<input;i++)
  {   
         System.out.print("Enter The Number : ");
         range[i]=obj.nextInt();
   
   total=total+range[i];
  }
     
            
  System.out.print("Entered Number Is :");
  for(int i=0;i<input;i++)
  {
   System.out.print(range[i]+" ");
  }
        System.out.println("Sum Of Input Numbers Is : "+total);
  }
   catch(Exception e)
  {
   System.out.println("Please Enter Valid Number !!");
  } 
  
 }
 public void Sub()
 {   int Total,input,input2;
  Scanner obj = new Scanner(System.in);
  System.out.println("Enter The Two Number for Subtract :");
  System.out.print("Enter The 1st Number : ");
  input=obj.nextInt();
     System.out.print("Enter The 2nd Number : ");
     input2=obj.nextInt();
  //if(input2>input)
  
    Total=input-input2;
    System.out.println("The Subtraction of "+input2+" - "+input+" is : "+Total);
  
    /*else
       Total=input-input2;
    System.out.println("The Subtraction of "+input+" - "+input2+" is : "+Total);*/
 }
 public void Multi()
 {   int i,Total=1,input;
  Scanner obj = new Scanner(System.in);
  System.out.println("Enter The Range Of Number For Multiplcation : ");
   input=obj.nextInt();
   int[] range=new int [input];
  for(i=0;i<input;i++)
  {   System.out.print("Enter The Number : ");
         range[i]=obj.nextInt();
   Total=Total*range[i];
  } 
  System.out.print("Entered Number are :");
  for(i=0;i<input;i++)
  {
   System.out.print(range[i]+" ");
  }
        System.out.println("\nMultiplication Of Input Numbers Is : "+Total);
 }
 public void SinValue()
 {    Scanner obj=new Scanner(System.in);
   System.out.print("Find The Value Sine ");
   System.out.println("Enter the Choice :");
   System.out.println("1. Enter the value in Degree.");
   System.out.println("2. Enter the value in Radian.");
   int input =obj.nextInt();
   double output,input2;
   if(input==1)
   {  
         System.out.println("Enter The Angle :");
    input2 =obj.nextDouble();
   double degree=Math.toRadians(input2);
   output=Math.sin(degree); 
   System.out.println("The Value of Sin("+input2+") is "+output);
   }
   else if(input==2)
   {
   System.out.println("Enter The Angle :");
    input2 =obj.nextInt();
   output=Math.sin(input2);
   System.out.println("The Value of Sin("+input2+") is "+output);
   }
   else
   {
    System.out.println("! Please Enter valid Nubmer !");
   }
 }
    public void CosValue()
 {    Scanner obj=new Scanner(System.in);
   System.out.print("Find The Value Cosine ");
   System.out.println("Enter the Choice :");
   System.out.println("1. Enter the value in Degree.");
   System.out.println("2. Enter the value in Radian.");
   int input =obj.nextInt();
   double output,input2;
   if(input==1)
   {  
         System.out.println("Enter The Angle :");
    input2 =obj.nextDouble();
   double degree=Math.toRadians(input2);
   output=Math.cos(degree); 
   System.out.println("The Value of Cos("+input2+") is "+output);
    }
   else if(input==2)
   {
   System.out.println("Enter The Angle :");
     input2 =obj.nextInt();
   output=Math.cos(input2);
   System.out.println("The Value of Cos("+input2+") is "+output);
   }
   else
   {
    System.out.println("! Please Enter valid Nubmer !");
   }
 }
 public void TanValue()
 {    Scanner obj=new Scanner(System.in);
   System.out.print("Find The Value Tangent ");
   System.out.println("Enter the Choice :");
   System.out.println("1. Enter the value in degree.");
   System.out.println("2. Enter the value in Radian.");
   double input =obj.nextInt();
   double output,input2;
   if(input==1)
   {  System.out.println("Enter The Angle :");
    input2 =obj.nextDouble();
   double degree=Math.toRadians(input2);
   output=Math.tan(degree); 
   System.out.println("The Value of Tan("+input2+") is "+output);
   }
   else if(input==2)
   {  System.out.println("Enter The Angle :");
    input2 =obj.nextInt();
   output=Math.tan(input2);
   System.out.println("The Value of Tan("+input2+") is "+output);
   }
   else
   { 
         System.out.println("! Please Enter valid Nubmer !");
   }
 }
 public void LogValue()
 {    double output,input;
   Scanner obj = new Scanner(System.in);
   System.out.println("<---- Find a value oF Log (Base 10) ---->\nEnter The Number : ");
   input =obj.nextDouble();
   output = Math.log10(input);
   System.out.println("The Value of Log10("+input+") is "+output);
 }
 public void Factorial()
 {   System.out.println("Find a Factorial, Enter The Number : ");
  Scanner obj= new Scanner(System.in);
  long  input=obj.nextInt();
  long  factorial=1;
  for(long j=input;j>=1;j--)
  {
   factorial=factorial*j;
  }
  System.out.println("The Factorial OF "+input+" is "+factorial);
 }
 public void Swap()
 {   System.out.println(" Enter The Two Number : ");
  Scanner obj= new Scanner(System.in);
  System.out.print("Enter The Value Of A : ");
  int input=obj.nextInt();
  System.out.print("Enter The Value Of B : ");
  int input2=obj.nextInt();
  input =input+input2;
  input2=input-input2;
  input = input-input2;
  System.out.println("The Value Of A : "+input+"\nThe Value Of B : "+input2);
 }
 public void SquareRoot()
 {     Scanner obj=new Scanner(System.in);
    System.out.print("Enter The Number For SquareRoot Value ");
    double input =obj.nextInt();
    double output = Math.sqrt(input);
    System.out.println("The squareRoot value of "+input+" is "+output);
 }
}
class Choice extends Operation
{
public void Disp()
   { 
    Scanner obj=new Scanner(System.in);
    loop: while(true)
      {
 System.out.println("\n\nPlease Chose The operation :\n");
 System.out.println(" 1. Addition");
 System.out.println(" 2. Subtraction");
 System.out.println(" 3. Multiplication");
 System.out.println(" 4. Value Of Sin");
    System.out.println(" 5. Value Of Cos");
 System.out.println(" 6. Value Of Tan");
 System.out.println(" 7. Value Of Log");
 System.out.println(" 8. Factorial");
 System.out.println(" 9. Swaping");
 System.out.println(" 10.SquareRoot");
 System.out.println(" 11.Exit\n");
 System.out.print("Enter The choice Number : ");
 int input =obj.nextInt();
 switch(input)
         {     case 1:
     Add();
         break ;
       case 2:
          Sub();
         break;
       case 3:
         Multi();
      break;
       case 4:
      SinValue();
     break;
       case 5:
         CosValue();
      break;
    case 6:
       TanValue();
       break;
    case 7:
        LogValue();
     break;
     case 8:
      Factorial();
       break;
    case 9:
       Swap();
       break;
    case 10:
       SquareRoot();
       break;
    case 11:
       break loop;
        default :
      System.out.println("!Please Enter  Valid Number !");
    }
     } 
 }
}
public class Calculator
{
 public static void main(String[] arg)
 {
  Choice obj=new Choice();
  obj.Disp();
 }
}



							
							

							
																			
													
												


Output :

Console Output:

Java Scientific Calculator Console Output
Java Scientific Calculator Console Output.
Announcement
Advertisement