# muliplication product of two integers but not display the answer.

Page 1 of 1

## 8 Replies - 3082 Views - Last Post: 15 March 2010 - 04:44 PMRate Topic: //<![CDATA[ rating = new ipb.rating( 'topic_rate_', { url: 'http://www.dreamincode.net/forums/index.php?app=forums&module=ajax&section=topics&do=rateTopic&t=162124&amp;s=0b42da8b4dfa71c476f2f91b7a2076ff&md5check=' + ipb.vars['secure_hash'], cur_rating: 0, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

### #1 donitnavy

Reputation: -5
• Posts: 4
• Joined: 15-March 10

# muliplication product of two integers but not display the answer.

Posted 15 March 2010 - 02:17 PM

method named product() to the Number() class that should compute the muliplication product of two integers but not display the answer.

Instead it should return the answer to the callimg method, which displays the answer...the "int product()" line you see below may not even supposed to be there..?

```/*
Author: Kent Cox
Date:
Subject: Module 2 Homework, Chapter 3: EXC #2a
Purpose: Compute the sum and differance of two arguments and display their results.

//code//
*/

public class Numbers

{
public static void main(String[] args)
{
int numA = 9;
int numB = 7;

sum(numA, numB); //calls method to calculat sum
difference(numA, numB); //calls method to calculate diff
product(numA, numB);
}
public static void sum(int x, int y)
{
// Add the two arguments and display the results
System.out.println("The sum of " + x + " and " + y + " is " + (x+y) + ".");
}

public static void difference(int x, int y)
{
// Subtract the second argument from the first and display the results
System.out.println("The difference between " + x + " and " + y + " is " + (x-y) + ".");
}
public static int product(int x, int y){
return x * y;
}
System.out println("product" + x + "and" + y +);
}
=

//end code

```

Admin Edit: Please use code tags when posting your code. Code tags are used like so =>

Thanks,
PsychoCoder

This post has been edited by donitnavy: 15 March 2010 - 03:53 PM

Is This A Good Question/Topic? 0

## Replies To: muliplication product of two integers but not display the answer.

### #2 erik.price

• D.I.C Lover

Reputation: 485
• Posts: 2,690
• Joined: 18-December 08

## Re: muliplication product of two integers but not display the answer.

Posted 15 March 2010 - 02:22 PM

So just make the method return the product instead of displaying it:
```
public static int product(int x, int y){
return x * y;
}

```

Then print it out from main.

### #3 donitnavy

Reputation: -5
• Posts: 4
• Joined: 15-March 10

## Re: muliplication product of two integers but not display the answer.

Posted 15 March 2010 - 02:30 PM

erik.price, on 15 March 2010 - 01:22 PM, said:

So just make the method return the product instead of displaying it:
```
public static int product(int x, int y){
return x * y;
}

```

Then print it out from main.

### #4 erik.price

• D.I.C Lover

Reputation: 485
• Posts: 2,690
• Joined: 18-December 08

## Re: muliplication product of two integers but not display the answer.

Posted 15 March 2010 - 02:31 PM

Um, why did you only quote why I said?

### #5 donitnavy

Reputation: -5
• Posts: 4
• Joined: 15-March 10

## Re: muliplication product of two integers but not display the answer.

Posted 15 March 2010 - 03:55 PM

```public class Numbers

{
public static void main(String[] args)
{
int numA = 9;
int numB = 7;

sum(numA, numB); //calls method to calculat sum
difference(numA, numB); //calls method to calculate diff
product(numA, numB);
}
public static void sum(int x, int y)
{
// Add the two arguments and display the results
System.out.println("The sum of " + x + " and " + y + " is " + (x+y) + ".");
}

public static void difference(int x, int y)
{
// Subtract the second argument from the first and display the results
System.out.println("The difference between " + x + " and " + y + " is " + (x-y) + ".");
}
public static int product(int x, int y){
return x * y;
}
System.out println("product" + x + "and" + y +);
}

```

This post has been edited by Dogstopper: 15 March 2010 - 04:07 PM

### #6 erik.price

• D.I.C Lover

Reputation: 485
• Posts: 2,690
• Joined: 18-December 08

## Re: muliplication product of two integers but not display the answer.

Posted 15 March 2010 - 04:07 PM

```System.out println("product" + x + "and" + y +);
```
This must be inside the main method. Also, you want to print the product returned from the method, not the variables x and y, as they do not have scope in main

### #7 Dogstopper

Reputation: 2950
• Posts: 11,217
• Joined: 15-July 08

## Re: muliplication product of two integers but not display the answer.

Posted 15 March 2010 - 04:09 PM

Similar topics merged. Please don't open multiple topics for the same problem

This post has been edited by Dogstopper: 15 March 2010 - 04:09 PM

### #8 donitnavy

Reputation: -5
• Posts: 4
• Joined: 15-March 10

## Re: muliplication product of two integers but not display the answer.

Posted 15 March 2010 - 04:30 PM

erik.price, on 15 March 2010 - 01:31 PM, said:

Um, why did you only quote why I said?

Trying helping a friend I am a C++ guy. Java is for the birds.

### #9 macosxnerd101

• Games, Graphs, and Auctions

Reputation: 11447
• Posts: 43,142
• Joined: 27-December 08

## Re: muliplication product of two integers but not display the answer.

Posted 15 March 2010 - 04:44 PM

So you quoted erik.price without asking a question b/c you do not like the language? If you have a question, please ask. However, if you do not, don't frivolously post, as it wastes other DICs time which could be better spent helping members with questions.