aspose file tools*
The moose likes Beginning Java and the fly likes How to combine two arrays within a loop? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "How to combine two arrays within a loop?" Watch "How to combine two arrays within a loop?" New topic
Author

How to combine two arrays within a loop?

Nick Hallloran
Greenhorn

Joined: Feb 09, 2010
Posts: 19
I am having troubles combing both arrays to execute within the loop. I have confused myself way to long with this simple program. I am supposed to write a program that reads 10 numbers and displays the distinct numbers. Example layout of the output is:

Enter an integer: 1
Enter an integer: 3
Enter an integer: 2
Enter an integer: 1
Enter an integer: 5
Enter an integer: 4
Enter an integer: 5
Enter an integer: 2
Enter an integer: 4
Enter an integer: 5
The number of distinct values is 5
1 3 2 5 4

My code is:
Ireneusz Kordal
Ranch Hand

Joined: Jun 21, 2008
Posts: 423
Hi,

use Set to display distinct values. I guess you want to display them in the order they were entered - LinkedHashSet is ideal to do this.
Look at this example:
Sridhar Santhanakrishnan
Ranch Hand

Joined: Mar 20, 2007
Posts: 317
Ireneusz Kordal wrote:Hi,

for( Integer i: set){
System.out.println( i );
}


Or just use
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to combine two arrays within a loop?