View Single Post
  #2 (permalink)  
Old 07-23-2008, 06:39 AM
Eranga's Avatar
Eranga Eranga is offline
Moderator
 
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 7,473
Rep Power: 11
Eranga has a spectacular aura aboutEranga has a spectacular aura about
Send a message via Yahoo to Eranga
Default
What you have tried upto now. Any attempt you take?

Anyway here is a simple code for the second question.

Code:
public class Numbers {

    public static void main(String[] args) {
        int valOne = 20;
        int valTwo = 37;
        
        Numbers num = new Numbers();
        num.sum(valOne, valTwo);
        num.difference(valOne, valTwo);
    }
    
    private void sum(int i, int j) {
        System.out.println("Sum of " + i + " and " + j + " = " + (i + j));
    }
    
    private void difference(int i, int j) {
        int diff = 0;
        if(i >= j) {
            diff = i - j;
        }
        else {
            diff = j - i;
        }
        System.out.println("Difference of " + i + " and " + j + " = " + diff);
    }

}
__________________
Use an appropriate Subject. "Help, urgent!" isn't one.
Someone helped you? their helpful post.
Help:Forums FAQ|How To Ask Questions The Smart WayResources:The Java Tutorials|Glossary for Java|NetBeans IDE|Sun DownloadsWeb:WritOnceTips:Is your IDE the best?|Which Application Server?
Reply With Quote