Java Class Question?
1 Answer(s)      5 years and 6 months ago
Posted in : Java Beginners

1. Create an application names Numbers whose main() method holds two interger variables Assign values to the variables pass both variables to methods names sum() and difference() Create the methods sum() and difference(); they computer the sum of and difference between the values of two arguments respectively each method should perform the appropriate computation and display the results.

2. add a method names product() to the Number class the product() method should compute the multiplication product of two integers but not display the answer instead it should return the answer to the calling method which displays the answer.


View Answers

September 6, 2011 at 11:20 AM

class Numbers 
    public void add(int a, int b){
        int c=a+b;
        System.out.println("Sum of numbers is: "+c);
    public void difference(int a, int b){
        int c=0;
        System.out.println("Difference of numbers is : "+c);
    public int product(int a, int b){
        int c=a*b;
        return c;
    public static void main(String[] args) 
        int i=5,j=10;
        Numbers n=new Numbers();
        int product=n.product(i,j);
        System.out.println("Product of numbers is: "+product);