1. Member 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);
}
}  Reply With Quote

2. ##  Originally Posted by Dru 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,

Jos  Reply With Quote

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
}```
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;
}```  Reply With Quote

#### Posting Permissions

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