Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 4 of 4

Thread: need help in AP Computer Science!

  1. #1
    Junior Member
    Join Date
    Sep 2011
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default need help in AP Computer Science!

    So basically, I'm a sophemore in highschool taking APCS and I'm having some trouble with my homework. Any help would be greatly appreciated. Soo what are the outputs for each of the statements in this code:

    public class MysteryReturn {
    public static void main(String[] args) {
    int x = 1;
    int y = 2;
    int z = 3;

    z = mystery(x, z, y); // Statement 1
    System.out.println(x + " " + y + " " + z); // Statement 2
    x = mystery(z, z, x); // Statement 3
    System.out.println(x + " " + y + " " + z); // Statement 4
    y = mystery(y, y, z); // Statement 5
    System.out.println(x + " " + y + " " + z); // Statement 6
    }

    public static int mystery(int z, int x, int y) {
    z--;
    x = 2 * y + z;
    y = x - 1;
    System.out.println(y + " " + z);
    return x;
    }
    }


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: need help in AP Computer Science!

    what are the outputs for each of the statements
    Do you have the javac and the java commands? If not you need to download the JDK and install it.
    Then you will be able to compile with javac and execute the program with java and see what those statements output.

  3. #3
    Junior Member
    Join Date
    Sep 2011
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: need help in AP Computer Science!

    the outputs are:
    3 0
    1 2 4
    4 3
    5 2 4
    8 1
    5 9 4

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: need help in AP Computer Science!

    Are those outputs correct? Is your question answered?

Similar Threads

  1. Non computer related hobbies
    By JavaPF in forum Totally Off Topic
    Replies: 36
    Last Post: March 8th, 2018, 10:12 AM
  2. Replies: 1
    Last Post: March 11th, 2011, 02:11 PM
  3. computer science help
    By hairyjewbear in forum Algorithms & Recursion
    Replies: 6
    Last Post: November 4th, 2010, 04:05 PM
  4. Database in a standalone computer
    By Abednego Setyawan in forum JDBC & Databases
    Replies: 1
    Last Post: April 7th, 2010, 09:24 PM
  5. Code wise working of Computer Algebra Systems
    By helloworld922 in forum Java Theory & Questions
    Replies: 1
    Last Post: July 7th, 2009, 07:45 AM

Tags for this Thread