What's new

Help Pasok ka naman Salamat.

G O Z A R U

Forum Expert
Elite
Joined
Apr 7, 2017
Posts
8,005
Solutions
1
Reaction
4,317
Points
2,470
Pahelp po mga lods Create a calculator program using arithmetic operation parang mali yung ginawa ko eh mano mano hnd isahan.dapat ata dun sa output ng program is belong yung addition,subtraction,multiplication,division.

Salamat po kaphc
 

Attachments

Last edited:
Java:
package phchelp;
import java.util.Scanner;

public class PhcHelp {


    public static void main(String[] args) {
       Scanner sc = new Scanner(System.in);
        System.out.println("1 for Addition");
        System.out.println("2 for Subtraction");
        System.out.println("3 for Multiplication");
        System.out.println("4 for Division");
        System.out.print("Select operation : ");
        int phc = sc.nextInt();
        System.out.print("Enter 1st Number :");
        int phcNum1 = sc.nextInt();
        System.out.print("Enter 2nd Number :");
        int phcNum2 = sc.nextInt();
        if(phc==1){
            int add1 = phcNum1+phcNum2;
            System.out.println("The addtion of 1st and 2nd number is : "+add1);
        }
       
        else if (phc==2){
            int sub1 = phcNum2-phcNum1;
            System.out.println("The subtraction 1st and 2nd number is : "+sub1);
       
    }
   
       
    }
   
}



Code:
output for addition
--------------------------------
1 for Addition
2 for Subtraction
3 for Multiplication
4 for Division
Select operation : 1
Enter 1st Number :2
Enter 2nd Number :5
The addtion of 1st and 2nd number is : 7

Code:
output for subtraction
-----------------------------------
1 for Addition
2 for Subtraction
3 for Multiplication
4 for Division
Select operation : 2
Enter 1st Number :5
Enter 2nd Number :10
The subtraction 1st and 2nd number is : 5

yan na yung logic pag patuloy mo nalang para sa multiplication and division
kaya nayan STI ka naman ehhahaha
 
Try mo to idol
1605250076561.png
 

Attachments

Java:
import java.util.*;
public class Arrithmetic {

    
    
    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
       Scanner in = new Scanner(System.in);
       int a, b, numInput = 0;
      
       System.out.println("Select Operator: ");
       System.out.println("1. Addition");
       System.out.println("2. Subtraction");
       System.out.println("3. Multiplication");
       System.out.println("4. Division");
       System.out.println("");
       System.out.print("Your Input: ");
       numInput = in.nextInt();
      
       if(numInput == 1){
           System.out.print("Enter first number: ");
           a = in.nextInt();
           System.out.print("Enter second number: ");
           b = in.nextInt();
           System.out.print("The sum is ");
           System.out.print(a+b);
       }
       else if(numInput == 2){
           System.out.print("Enter first number: ");
           a = in.nextInt();
           System.out.print("Enter second number: ");
           b = in.nextInt();
           if(a>b){
               System.out.print("The difference is ");
               System.out.print(a-b);
           }
           else{
               System.out.print("The difference is ");
               System.out.print(b-a);
           }
       }
          
        else if(numInput == 3){
           System.out.print("Enter first number: ");
           a = in.nextInt();
           System.out.print("Enter second number: ");
           b = in.nextInt();
           System.out.print("The product is ");
           System.out.print(a*b);
           }
      
       else if(numInput == 4){
           System.out.print("Enter first number: ");
           a = in.nextInt();
           System.out.print("Enter second number: ");
           b = in.nextInt();
           System.out.print("The quotient is ");
           System.out.print(a/b);
           }
       }
        
    
    
       }
 

Similar threads

Back
Top