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: help with homework - simple arrays

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

    Default POST DELETED

    POST DELETED
    Last edited by sensoryctascale; April 21st, 2011 at 04:57 PM.


  2. #2
    Junior Member
    Join Date
    Apr 2011
    Posts
    6
    Thanks
    0
    Thanked 1 Time in 1 Post

    Default Re: help with homework - simple arrays

    HI,

    I notice that there are two of you with the same assignment.


    //…Stuff
    System.out.println("Enter values for first set, ending with -1");
     
    String firstSet = new String();
    String secondSet = new String();
     
    int setA = input.nextInt();
    int setB = input.nextInt();
     
    while (setA != -1) {
        setA = input.nextInt();
        if (setA != -1)
            firstSet = firstSet + setA + " ";
    }
     
    //OTHER STUFF…

    Think about the order that this is doing things.

    What happens when you enter these values for the first set?

    -1 -1 2 3 4 5 6 7 8 9

    What happens when you enter these values for the first set?

    1 -1 2 3 4 5 6 7 8 9

    Can you see where the first two value are 'disappearing' now?

    Also as a side note make sure you post in the correct section. I'm not sure how strict this forum is (my first time/post) but some forums can get pretty touchy about such things.

    Suisse

  3. #3
    Grand Poobah
    Join Date
    Mar 2011
    Posts
    1,465
    My Mood
    Grumpy
    Thanks
    0
    Thanked 158 Times in 149 Posts

    Default Re: help with homework - simple arrays

    int setA = input.nextInt();  
    int setB = input.nextInt();
    What are these 2 lines for? Currently you read the first 2 numbers into these variables and then throw them away.

  4. #4
    Think of me.... Mr.777's Avatar
    Join Date
    Mar 2011
    Location
    Pakistan
    Posts
    1,136
    My Mood
    Grumpy
    Thanks
    20
    Thanked 82 Times in 78 Posts
    Blog Entries
    1

    Default Re: help with homework - simple arrays

    I think i've been told you in the form of pseudocode on another thread in What's Wrong with my Code? Forum. Go and search there...

Similar Threads

  1. Homework
    By jdonaldson in forum What's Wrong With My Code?
    Replies: 1
    Last Post: March 9th, 2011, 10:09 AM
  2. Homework help
    By cd247 in forum What's Wrong With My Code?
    Replies: 2
    Last Post: October 11th, 2009, 05:56 PM
  3. need help with homework!
    By programmer12345 in forum Java Theory & Questions
    Replies: 2
    Last Post: September 27th, 2009, 05:34 AM
  4. Homework - using 'IF' for 'For Loops'
    By Enzo in forum Loops & Control Statements
    Replies: 5
    Last Post: September 16th, 2009, 10:52 AM
  5. [SOLVED] What is cast operator and how to use it?
    By napenthia in forum Java Theory & Questions
    Replies: 11
    Last Post: April 27th, 2009, 06:11 AM