0% found this document useful (0 votes)
19 views

Java Packages Demo

Uploaded by

zoom temp
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
19 views

Java Packages Demo

Uploaded by

zoom temp
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

PRACTICE QUESTION

Q1) Create a package with one class containing 4 methods for the 4 operations to do
addition, subtraction, multiplication, division. Import this package and display the result for
the following questions:
i) 3+10
ii) 24-59
iii) 15*25
iv) 24/5

Ans) Code

package mycalculator;
import java.util.*;

public class Operations


{
public void add(int a, int b){
System.out.println("The sum is: " + (a+b));
}
public void subtract(int a, int b){
System.out.println("The difference is: " + (a-b));
}
public void multiply(int a, int b){
System.out.println("The product is: " + (a*b));
}
public void divide(int a, int b){
System.out.println("The quotient is: " + (a/b));
}
}
import mycalculator.Operations;

public class Calculator


{
public static void main(String args[]){
Operations obj = new Operations();
obj.add(3,10);
obj.subtract(24,59);
obj.multiply(15,25);
obj.divide(24,5);
}
}

You might also like