🔒 Closed Pasok ka naman Salamat.

Status
Not open for further replies.
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

  • IMG_20201113_132114.webp
    IMG_20201113_132114.webp
    69.7 KB · Views: 21
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
 
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);
           }
       }
        
    
    
       }
 
Status
Not open for further replies.

About this Thread

  • 14
    Replies
  • 482
    Views
  • 4
    Participants
Last reply from:
ZXCHkr

Online now

Members online
967
Guests online
2,450
Total visitors
3,417

Forum statistics

Threads
2,276,141
Posts
28,967,846
Members
1,231,131
Latest member
Yrrojan
Back
Top