How to execute the if loop just once even if the condition gets true again?
I need The random numbers to keep regenerating till 8 times but with executing the if loop just the first time the number 3 is generator and not if it get regenerated again.
This is my code:
import java.util.*;
public class ExecuteIfJustOnce
{
public static void main(String Laythe[])
{
Random Generate = new Random();
int RandomNumber;
for(int i=0; i < 8; i++)
{
RandomNumber = Generate.nextInt(5);
System.out.println(RandomNumber);
if (RandomNumber == 3)
{
System.out.println("This will be printed once even if the " +
"number 3 is occured next time");
}
// I need The random numbers to keep regenerating till 8 times
// but with executing the if loop just the first time the number 3
// is generator and not if it get regenerated again;
}
}
}

New Topic/Question
Reply



MultiQuote








|