Results 1 to 2 of 2
- 05-08-2012, 09:23 PM #1
Senior Member
- Join Date
- Apr 2012
- Posts
- 115
- Rep Power
- 0
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
Ok so I populated the array...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(); } } }
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?
- 05-08-2012, 09:45 PM #2
Moderator
- Join Date
- Jul 2010
- Location
- California
- Posts
- 1,619
- Rep Power
- 5
Similar Threads
-
while loop tries 20 times before giving up
By JMAsterson in forum New To JavaReplies: 3Last Post: 04-10-2012, 10:02 PM -
Using Java AWT and Canvas to draw an array of circles (big headache)
By RET80 in forum New To JavaReplies: 16Last Post: 01-30-2012, 05:36 AM -
Is it Possible? Array elements Initialized in Loop, can it be viewed outside loop?
By JPH in forum New To JavaReplies: 1Last Post: 10-01-2011, 02:12 AM -
NullPointerException Headache
By denno in forum New To JavaReplies: 17Last Post: 04-05-2011, 08:13 AM -
cant print 2d array(giving null values)
By fneeks in forum New To JavaReplies: 1Last Post: 04-07-2010, 08:48 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks