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 7 of 7

Thread: processing arrays

  1. #1
    Junior Member
    Join Date
    Dec 2012
    Posts
    7
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default processing arrays

    I currently have a list of numbers
    int[][] cube = new int [56][3];
    //numbers are input here
    the variable cube only has (approximately) 4 different numbers in it.
    e.g. 1,1,1,5,5,5,2,2,5,2,2,1,1,1.
    The numbers range from 0 to 1000.
    I want to output the numbers, with no repeats.
    e.g. 1,5,2.
    I am currently using the code
    int[][] cube = othermethod(args);
    int[][] temp = new int[32][3];
    int counter;
    int reg=0;
    for(counter=0;counter<56;counter++){
    	if(
    	temp[reg-1][0]==cube[counter][0]&&
    	temp[reg-1][1]==cube[counter][1]&&
    	temp[reg-1][2]==cube[counter][2]){
    	}else{
    	temp[reg][0]=cube[counter][0];
    	temp[reg][1]=cube[counter][1];
    	temp[reg][2]=cube[counter][2];
    	reg++;
    Note. This code does not work how I want it to.


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: processing arrays

    I want to output the numbers, with no repeats.
    Did you do any design before writing the code? What is the technique you are using to detect the numbers that you want to print out?
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Junior Member
    Join Date
    Dec 2012
    Posts
    7
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default Re: processing arrays

    I didn't do any design, I'm new to Java and just messing around with code to see what is possible.
    The if statement checks if cube is the same as temp. If it is, it does nothing. If it isn't, it updates temp.
    This doesn't work, because temp (before update) is always 0.
    I modified the code so that temp is the previous cube. This does not give the same number more than once in a row, but still gives repetitions.
    Once I have the numbers stored in temp, I can access them from another class, or use a for loop with print line.
    I only need help with eliminating repeated numbers.

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: processing arrays

    I didn't do any design
    It's often much quicker to design code before writing it with this type of logic problem. Randomly trying different code sequences can waste a lot of time.

    checks if cube is the same as temp
    What is in temp? What does "is the same" mean? The arrays are different sizes. I don't see how they can be the same.

    A start on a design:
    If you had a pile of playing cards and wanted to make a pile of unique face values ignoring suits, how would you do it? If you Pick up a card from the top of the pile, how do you decide if it should go in the unique pile?
    If you don't understand my answer, don't ignore it, ask a question.

  5. #5
    Junior Member
    Join Date
    Dec 2012
    Posts
    7
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default Re: processing arrays

    Quote Originally Posted by Norm View Post
    If you had a pile of playing cards and wanted to make a pile of unique face values ignoring suits, how would you do it? If you Pick up a card from the top of the pile, how do you decide if it should go in the unique pile?
    That's what I'm trying to do. I have a few solutions, but all of them take many lines and are inefficient.
    I wanted to know if there was a simple command to do that.

    Quote Originally Posted by Norm View Post
    What is in temp? What does "is the same" mean? The arrays are different sizes. I don't see how they can be the same.
    The test is if temp[0][0] == cube[0][0] and temp[0][1] == cube[0][1] and temp[0][2] == cube[0][2].
    Ignore this if you don't understand it, it doesn't work anyway.

  6. #6
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: processing arrays

    if there was a simple command to do that
    Not that I know of. Nothing even close.

    test is if temp[0][0] == cube[0][0] and temp[0][1] == cube[0][1] and temp[0][2] == cube[0][2].
    That only looks at three elements of the arrays.
    If you don't understand my answer, don't ignore it, ask a question.

  7. #7
    Junior Member
    Join Date
    Dec 2012
    Posts
    7
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default Re: processing arrays

    I'll use one of my convoluted approaches.
    Thanks for the help.

Similar Threads

  1. Image Processing
    By vigneshwaran in forum AWT / Java Swing
    Replies: 1
    Last Post: November 27th, 2012, 07:33 AM
  2. Re: Image Processing
    By rajkula in forum File I/O & Other I/O Streams
    Replies: 1
    Last Post: August 3rd, 2012, 10:41 AM
  3. Processing
    By KevinWorkman in forum Other Programming Languages
    Replies: 4
    Last Post: September 6th, 2011, 10:30 AM
  4. Processing Arrays
    By av8 in forum What's Wrong With My Code?
    Replies: 4
    Last Post: June 27th, 2011, 06:19 AM
  5. Image Processing
    By subash in forum File I/O & Other I/O Streams
    Replies: 4
    Last Post: June 8th, 2011, 08:40 AM

Tags for this Thread