Sample Calculator! :)

import java.util.Scanner; public class Main { public static int sum(int num1,int num2){ return num1+num2; } public static int sub(int num1,int num2){ return num1-num2; } public static int mul(int num1,int num2){ return num1*num2; } public static double divi(int num1,int num2){ return num1/num2; } public static double per(int num1,int num2){ return num1%num2; } public static void main(String[] args){ Scanner sc = new Scanner(System.in); System.out.println("Enter number:"); int num1= sc.nextInt(); System.out.println("Enter the second number:"); int num2= sc.nextInt(); System.out.println("\n1.Addition\n2.Subtraction\n3.Multiplication\n4.Divison:"); int n = sc.nextInt(); int sum1=sum(num1,num2); int sub1=sub(num1,num2); int mul1=mul(num1,num2); double divi1=divi(num1,num2); double per1=per(num1,num2); if(n==1){ System.out.println(" \nAddition of "+num1+" and "+num2+" is "+sum1); } else if(n==2){ System.out.println(" \nSubtraction of "+num1+" and "+num2+" is "+sub1); } else if(n==3){ System.out.println(" \nMuliplication of "+num1+" and "+num2+" is "+mul1); } else if(n==4){ System.out.println("\nDivison of "+num1+" and "+num2+" is "+divi1); }else if(n==5){ System.out.println("\nto find remainder of "+num1+" and "+num2+" is "+per1); }else{ System.out.println("\n1 Please Enter a valid number between from 1 to 5!"); } } } Check this out!!

Mar 11, 2025 - 17:20
 0
Sample Calculator! :)

Image description

import java.util.Scanner;
public class Main
{
public static int sum(int num1,int num2){
   return num1+num2;
}
public static int sub(int num1,int num2){
   return num1-num2;
}
public static int mul(int num1,int num2){
   return num1*num2;
}
public static double divi(int num1,int num2){
   return num1/num2;
}
public static double per(int num1,int num2){
   return num1%num2;
}

public static void main(String[] args){
   Scanner sc = new Scanner(System.in);
   System.out.println("Enter number:");
   int num1= sc.nextInt();
   System.out.println("Enter the second number:");
   int num2= sc.nextInt();
   System.out.println("\n1.Addition\n2.Subtraction\n3.Multiplication\n4.Divison:");
   int n = sc.nextInt();
   int sum1=sum(num1,num2);
   int sub1=sub(num1,num2);
   int mul1=mul(num1,num2);
   double divi1=divi(num1,num2);
   double per1=per(num1,num2);
   if(n==1){
       System.out.println(" \nAddition of "+num1+" and "+num2+" is "+sum1);
   }
   else if(n==2){
       System.out.println(" \nSubtraction of "+num1+" and "+num2+" is "+sub1);
   }
   else if(n==3){
       System.out.println(" \nMuliplication of "+num1+" and "+num2+" is "+mul1);
   }
   else if(n==4){
       System.out.println("\nDivison of "+num1+" and "+num2+" is  "+divi1);
   }else if(n==5){
       System.out.println("\nto find remainder of "+num1+" and "+num2+" is "+per1);
   }else{
       System.out.println("\n1 Please Enter a valid number between from 1 to 5!");
   }
}

}

Check this out!!