# Thread: Methods Problem Exercise

1. Member Join Date
Jul 2014
Posts
3
Rep Power
0

## Methods Problem Exercise

1.***** Write a program whose main() method hold two integer variables.* Assign values to the variables.* Create two additional methods, sum() and difference(), that compute the sum and difference between the values of the two variables, respectively.* Each method should perform the computation and display the result.* In turn, call each of the two methods from main(), passing the values of the two integer variables.
*
*** Add a method named product() to the program.* 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 main() program, which display the answer.
*
2.***** Write a program whose main() method hold an integer value, and in turn passes the value to a method that squares the number and a method that cubes the number.* The main() method prints the results.* Create two methods that respectively square and cube an integer that is passed to them, returning the calculated value.
guys please help me to answer this .THANKYOU   Reply With Quote

2. Senior Member Join Date
Jan 2013
Location
Northern Virginia, United States
Posts
6,226
Rep Power
13

## Re: Methods Problem Exercise

First you need to submit your attempt at doing this yourself. Then we will guide you into fixing any problems you encounter. If you
post any code, please place it between [code][/code] tags.

Regards,
Jim  Reply With Quote

3. Member Join Date
Jul 2014
Posts
3
Rep Power
0

## Re: Methods Problem Exercise

public class Compute
{
public static void main(String[] args)
{
int num1;
int num2;
System.out.println("The computed value of the two numbers");
subtract(50,5);
System.out.println("Prepared by: Virgie B. Loyola");
}
public static void add (int num1, int num2)
{
int sum;
sum= num1 + num2;
System.out.println("The sum of two numbers is " +sum);
}
public static void subtract (int num1,int num2)
{
int diff;
diff = num1 - num2;
System.out.println("The differences of two numbers is " + diff);
}
}

My Prof.tod us that this is the some example.:) please help me guys i really dont know ehat to do :(((  Reply With Quote

4. Member Join Date
Jul 2014
Posts
3
Rep Power
0

## Re: Methods Problem Exercise

public class Compute
{
public static void main(String[] args)
{
int num1;
int num2;
System.out.println("The computed value of the two numbers");
subtract(50,5);
System.out.println("Prepared by: Virgie B. Loyola");
}
public static void add (int num1, int num2)
{
int sum;
sum= num1 + num2;
System.out.println("The sum of two numbers is " +sum);
}
public static void subtract (int num1,int num2)
{
int diff;
diff = num1 - num2;
System.out.println("The differences of two numbers is " + diff);
}
}  Reply With Quote

5. ## Re: Methods Problem Exercise Originally Posted by Jonna Rose Maala Help with what? Ask a specific question get a specific answer.  Reply With Quote

6. ## Re: Methods Problem Exercise

it prints the sum and differences...what is there to understand?

gothru the java tutorial..  Reply With Quote

#### Tags for this Thread

this in a static context #### Posting Permissions

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