8 Replies - 2105 Views - Last Post: 15 March 2010 - 04:44 PM Rate Topic: -----

#1 donitnavy  Icon User is offline

  • New D.I.C Head

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

muliplication product of two integers but not display the answer.

Posted 15 March 2010 - 02:17 PM

can not figure out how to add the muliplicaiton product. please help


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 => :code:

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  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 485
  • View blog
  • 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.
Was This Post Helpful? 0
  • +
  • -

#3 donitnavy  Icon User is offline

  • New D.I.C Head

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

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

Posted 15 March 2010 - 02:30 PM

View Posterik.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.

Was This Post Helpful? -3
  • +
  • -

#4 erik.price  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 485
  • View blog
  • 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?
Was This Post Helpful? 0
  • +
  • -

#5 donitnavy  Icon User is offline

  • New D.I.C Head

Reputation: -5
  • View blog
  • 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

Was This Post Helpful? 0
  • +
  • -

#6 erik.price  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 485
  • View blog
  • 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

Please use the code tags :code:

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
Was This Post Helpful? 1
  • +
  • -

#7 Dogstopper  Icon User is offline

  • The Ninjaducky
  • member icon



Reputation: 2870
  • View blog
  • Posts: 11,023
  • 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 :crazy:

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

Was This Post Helpful? 0
  • +
  • -

#8 donitnavy  Icon User is offline

  • New D.I.C Head

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

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

Posted 15 March 2010 - 04:30 PM

View Posterik.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.
Was This Post Helpful? -2
  • +
  • -

#9 macosxnerd101  Icon User is online

  • Self-Trained Economist
  • member icon




Reputation: 10397
  • View blog
  • Posts: 38,470
  • 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.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1