I'm trying to add pauses to a for loop in Java (BlueJ). When I use Thread.sleep(1000)
, I end up with an exception: "unreported exception java.lang.InterruptedException must be caught or declared to be thrown"
What could be wrong with the code resulting in the exception:
public class R {
private boolean a;
private boolean b;
if(a && b) {
String[]Array = {"x","y","z"};
for(int i = 0; i < Array.length; i++, Thread.sleep(1000))
{
System.out.print(Array[i]);
}
}
}
I want the end result to be the following:
x
//delay
y
//delay
z