Results 1 to 3 of 3
Thread: Help with my homework thread
 01262010, 06:43 PM #1Member
 Join Date
 Jan 2010
 Posts
 1
 Rep Power
 0
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;
predictSum();
predictDiff();
}
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);
}
}
 01262010, 07:07 PM #2
 Join Date
 Sep 2008
 Location
 Voorschoten, the Netherlands
 Posts
 14,422
 Blog Entries
 7
 Rep Power
 28
 01262010, 10:34 PM #3
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).
Example:
This one has no return type. Also known as void:
Java Code:public static void methodOne() { //implementation here }
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

help with homework
By pinkdiamondgail in forum Advanced JavaReplies: 7Last Post: 04072009, 01:34 AM 
Homework help...
By robrobrob in forum New To JavaReplies: 4Last Post: 10172008, 04:24 AM 
Need help with homework.
By JavaNewbie0000 in forum New To JavaReplies: 2Last Post: 07312008, 03:06 PM 
thread homework
By integralli in forum Threads and SynchronizationReplies: 6Last Post: 06212008, 04:34 PM 
Problem using thread +rmi in my homework
By IbrahimAbbas in forum Threads and SynchronizationReplies: 10Last Post: 04142008, 09:24 PM
Bookmarks