Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Answers Viewqa Java-Beginners Java Class Question?

Have Programming Question? Ask it here!
 
 
 


bob
Java Class Question?
1 Answer(s)      2 years and 11 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.


Advertisement
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;
        if(a>b){
            c=a-b;
        }
        else{
        c=b-a;
        }
        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();
        n.add(i,j);
        n.difference(i,j);
        int product=n.product(i,j);
        System.out.println("Product of numbers is: "+product);
    }
}


Related Tutorials/Questions & Answers:
Advertisements
Advertisements
 

 

 

DMCA.com