Java Class Question?

Java Class Question?

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;
        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);
    }
}

Ads









Related Tutorials/Questions & Answers:
Inner class - Java Interview Questions
Core Java Interview Questions Page 2, Core Java QuestionQ
Advertisements
write those 3 questions (class)
java questions
java questions
Java Questions
Java Questions
Core Java Interview Questions!
java questions
java questions
java questions
java questions
java Questions
Java Questions & Java FAQ
Java Interview Questions
Questions about Java's String pool
Interview Questions - What is Java?
Java interview questions and answers
Java - Java Interview Questions
java - Java Interview Questions
Interview Questions - Where Java is used?
Java interview questions
Interview Questions - How Java is Used?
java - Java Interview Questions
Java - Java Interview Questions
Java - Java Interview Questions
Java Interview Questions - Page 1
constructor - Java Interview Questions
HASHSET - Java Interview Questions
j2ee - Java Interview Questions
Collection of Large Number of Java Interview Questions!

Ads