is a random number from 1 to 37 that outputs seven numbers.
the result of the two pieces of code is the same.
I would like to ask what role while (true) plays.
class Rnd_36_7
{
public static void main(String[] args)
{
int a[] = new int[7];
for( int i=0;i<a.length;iPP)
{
one_num:
while(true)
{
a[i] = (int)( Math.random()*36 ) +1;
for( int j=0;j<i;jPP ){
if( a[i]==a[j] ) continue one_num;
}
break;
}
}
for( int num: a) System.out.print( num+" " );
System.out.println();
}
}
package j36_7;
public class Java36_7 {
public static void main(String[] args) {
// TODO Auto-generated method stub
int []a = new int[7];
for(int i= 0; i < a.length;iPP)
{
// loop:
// while(true)
// {
a[i]=(int)(Math.random()*36)+1;
loop:
for(int j=0;j<i;jPP)
{
if(a[i]==a[j])
{
continue loop;
}
}
// break;
// }
}
for(int num : a)
{
System.out.print(num+" ");
}
}
}