Results 1 to 3 of 3
  1. #1
    Dru is offline Member
    Join Date
    Jan 2010
    Rep Power

    Default Help with my homework thread

    Hello all, i have to take java to finish my degree this year and im having a hard time wrapping my head around things, right when i think i got it....i loose it. So if some of you pros:) dont mind helping i'd appreciate the guidance.

    Im current starting the use of methods and classes, below is the description of the problem i have to write code for and what i've written so far which doesnt seem to work.

    (problem) create an application named Numbers who's main() method hold two integer variables. Assign values to the variables. Pass both variables to mehtods named sum() and difference (); they compute he sum of and difference between the values of two arguments, respectively. Each method should perform the appropriate computation and display the results.

    (havent gotten this far yet)

    (2nd half of the problem) Add a method named product() to the numbers 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.

    public class Numbers
    public static void main(String[] args)
    int nNum1 = 12;
    int nNum2 = 4;
    public static void predictSum()
    int sum;
    sum = nNum1 + nNum2;
    System.out.prinln(" The sum of numbers on and two is" + sum);
    public static void predictDiff()
    int diff;
    diff = nNum1 - nNum2;
    System.out.println(" The difference between the numbers is" + diff);

  2. #2
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Voorschoten, the Netherlands
    Blog Entries
    Rep Power


    Quote Originally Posted by Dru View Post
    Pass both variables to mehtods named sum() and difference ();
    That phrase is crucial; in your code you're not passing anything and btw, you didn't name your methods sum( ... ) or difference( ... ).

    kind regards,


  3. #3
    Lil_Aziz1's Avatar
    Lil_Aziz1 is offline Senior Member
    Join Date
    Dec 2009
    United States
    Rep Power


    The second half of the problem is stating that the product(int x, int y) method should have a return type corresponding to the answer (which should be an int).


    This one has no return type. Also known as void:

    Java Code:
    public static void methodOne() {
         //implementation here
    This has a return type of String:

    Java Code:
    public static [B]String[/B] methodTwo() {
         //implementation that will return a [B]String[/B]
         String s = "hi";
         return s;
    "Experience is what you get when you don't get what you want" (Dan Stanford)
    "Rise and rise again until lambs become lions" (Robin Hood)

Similar Threads

  1. help with homework
    By pinkdiamondgail in forum Advanced Java
    Replies: 7
    Last Post: 04-07-2009, 01:34 AM
  2. Homework help...
    By robrobrob in forum New To Java
    Replies: 4
    Last Post: 10-17-2008, 04:24 AM
  3. Need help with homework.
    By JavaNewbie0000 in forum New To Java
    Replies: 2
    Last Post: 07-31-2008, 03:06 PM
  4. thread homework
    By integralli in forum Threads and Synchronization
    Replies: 6
    Last Post: 06-21-2008, 04:34 PM
  5. Problem using thread +rmi in my homework
    By IbrahimAbbas in forum Threads and Synchronization
    Replies: 10
    Last Post: 04-14-2008, 09:24 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts