Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

How to prevent number duplication in Java.

807605Jun 12 2007 — edited Jun 12 2007
How do i prevent number duplication in this program. Basically so that i don't have to enter the same number again

here's the code:
   

import java.awt.*;
import hsa.Console;

public class BubbleSort_Strings
{
    static Console c;           // The output console

    public static void main (String[] args)
    {
        c = new Console ();

        c.println ("\t\t\tIPOD Downloads\n\n");
        c.print ("Enter the number of songs: ");
        int max = c.readInt ();
        c.println ();

        String song[] = new String [max];
        String tempSong;


        for (int i = 0 ; i <= max - 1 ; i = i + 1)
        {
            c.print ("Enter the name of song " + (i + 1) + ": ");
            song  = c.readLine ();
c.println ();
} //end for i

//sort the song names in the array alphabetically
for (int x = 0 ; x < max - 1 ; x++)
{
for (int y = x + 1 ; y < max ; y++)
{

if (song [x].compareTo (song [y]) > 0)
{
tempSong = song [x];
song [x] = song [y];
song [y] = tempSong;

} //end if
} //end for y
} //end for x

c.println ("Your songs have now been sorted:");
c.println ();

for (int z = 0 ; z <= max - 1 ; z = z + 1)
{
c.println (song [z]);
} //end for z



} // main method
} // BubbleSort_Strings class

Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jul 10 2007
Added on Jun 12 2007
11 comments
197 views