jeudi 12 mars 2015

How do i match two subscripts in an array?



System.out.println("\nPlease enter 7 unique numbers from 1 to 80.");



for(int i = 0; i<user.length; i++)
{
System.out.print("\nPlease enter number " + (i+1)+": ");
user[i] = sc.nextInt();
while(user[i]<1 || user[i] > 80)
{
System.out.println("\nPlease enter numbers from 1 to 80");
user[i] = sc.nextInt();
}

for(int j = 0; j<user.length; j++)
{
if (user[i] == user[j])
{
System.out.print("\nPlease enter a unique number: ");
user[i] = sc.nextInt();
while(user[i]<1 || user[i] > 80)
{
System.out.println("\nPlease enter numbers from 1 to 80");
user[i] = sc.nextInt();
}

}
}
}


i just need to know how to tell if two subscripts in the array are the same.


the initial declaration of the array was: int[] user = new int [7]; The game I'm making is Kern btw.




Aucun commentaire:

Enregistrer un commentaire