Results 1 to 2 of 2
  1. #1
    EscSequenceAlpha is offline Senior Member
    Join Date
    Apr 2012
    Posts
    115
    Rep Power
    0

    Default This loop array stuff is giving me a headache

    what I want to do is print out every member of the array after your input but only print them if they are unique

    Java Code:
    package chapter_vii;
    
    import java.util.Scanner;
    
    public class DuplicateElimination_7_12 
    {
    	public static void main(String[] args)
    	{
    		Scanner input = new Scanner(System.in);
    		
    		int number;
    		int[] collection = new int[5]; 
    		
    		for ( int i = 1 ; i <= 5 ; i++ )
    		{
    			System.out.println("Please input a number");
    			number = input.nextInt();
    			collection[i-1] = number;
    			
    			for ( int j = 0 ; j < collection.length ; j++ )
    			{
    				if (number != collection[j])
    				{
    					System.out.print(collection[j]);
    				}
    			}
    			System.out.println();
    		}
    	}
    }
    Ok so I populated the array...
    I use the second loop to check through every member of array
    if that member does not equal the number print it

    but as with me, I can not read this kind of logic... because my results are

    Please input a number
    3
    0000
    Please input a number
    6
    3000
    Please input a number
    7
    3600
    Please input a number
    6
    370
    Please input a number
    8
    3676

    ridiculous.

    whats the solution here and what on earth was I doing here?

  2. #2
    doWhile is offline Moderator
    Join Date
    Jul 2010
    Location
    California
    Posts
    1,641
    Rep Power
    7

    Default Re: This loop array stuff is giving me a headache

    I don't understand what output you expect...please type out for us what your expected/required output is.

Similar Threads

  1. while loop tries 20 times before giving up
    By JMAsterson in forum New To Java
    Replies: 3
    Last Post: 04-10-2012, 10:02 PM
  2. Replies: 16
    Last Post: 01-30-2012, 05:36 AM
  3. Replies: 1
    Last Post: 10-01-2011, 02:12 AM
  4. NullPointerException Headache
    By denno in forum New To Java
    Replies: 17
    Last Post: 04-05-2011, 08:13 AM
  5. cant print 2d array(giving null values)
    By fneeks in forum New To Java
    Replies: 1
    Last Post: 04-07-2010, 08:48 PM

Posting Permissions

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