Results 1 to 6 of 6
Like Tree1Likes
  • 1 Post By jim829

Thread: Methods Problem Exercise

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

    Smile 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

  2. #2
    jim829 is online now Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    3,661
    Rep Power
    5

    Default 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
    Jonna Rose Maala likes this.
    The Java™ Tutorial | SSCCE | Java Naming Conventions
    Poor planning our your part does not constitute an emergency on my part.

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

    Default 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");
    add(2,20);
    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 :(((

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

    Default 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");
    add(2,20);
    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);
    }
    }

  5. #5
    Junky's Avatar
    Junky is offline Grand Poobah
    Join Date
    Jan 2011
    Location
    Dystopia
    Posts
    3,798
    Rep Power
    7

    Default Re: Methods Problem Exercise

    Quote Originally Posted by Jonna Rose Maala View Post
    please help
    Help with what? Ask a specific question get a specific answer.

  6. #6
    RamyaSivakanth's Avatar
    RamyaSivakanth is offline Senior Member
    Join Date
    Apr 2009
    Location
    Chennai
    Posts
    837
    Rep Power
    6

    Default Re: Methods Problem Exercise

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

    gothru the java tutorial..
    Ramya:cool:

Similar Threads

  1. problem with an exercise
    By psp300xxx in forum New To Java
    Replies: 1
    Last Post: 12-09-2013, 07:47 PM
  2. Problem with BlueJ Exercise
    By TomFahey in forum New To Java
    Replies: 4
    Last Post: 05-29-2013, 05:44 PM
  3. Problem with an exercise in java
    By chkontog in forum New To Java
    Replies: 2
    Last Post: 11-19-2012, 12:46 PM
  4. Problem in an exercise
    By Honest989 in forum New To Java
    Replies: 1
    Last Post: 11-10-2010, 09:08 PM
  5. Exercise problem, how was this output achieved?
    By bs3ac in forum New To Java
    Replies: 8
    Last Post: 08-06-2010, 02:38 PM

Tags for this Thread

Posting Permissions

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