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









Related Tutorials/Questions & Answers:
question1 - Java Beginners
java class - Java Interview Questions
Advertisements
inner class - Java Interview Questions
Core Java Interview Questions Page 2, Core Java QuestionQ
abstract class - Java Interview Questions
Pattern class - Java Interview Questions
OBJECT CLASS - Java Interview Questions
Inner class - Java Interview Questions
abstract class - Java Server Faces Questions
abstract class - Java Server Faces Questions
where singleton class used in java - Java Interview Questions
write those 3 questions (class)
Java - Java Interview Questions
Difference between extends thread class vs implements runnable interface - Java Interview Questions
Design a class named BankAccount to hold datas for a bank account in Java using Bluej Software - Java Interview Questions
can i restrict a class that it will not allows create more than two objects - Java Interview Questions
How to call business deleget class(EJB) from JSF Page? - Java Server Faces Questions
java questions - Java Interview Questions
clone() method of object class - Java Interview Questions
Java class
Core Java Interview Questions!
java - Java Interview Questions
java questions
java class
java - Servlet Interview Questions
java class
java questions
JAVA QUESTIONS - Java Beginners
interview questions - Java Interview Questions
Java Questions
Java Questions
interview - Java Interview Questions
Java Questions
java - Java Interview Questions
Java Interview Questions
jvm - Java Interview Questions
Struts - Java Interview Questions
Java Questions & Java FAQ
help me - Java Interview Questions
Questions about Java's String pool
java questions
java questions
java questions
java questions
java Questions
Java inner class and static nested class
java certification questions - Java Beginners
java - Java Interview Questions
java - JSP-Interview Questions
Java Class Size

Ads