+ 1
How to print this in java ? 15 10 15 10 15 10 15 10........
2 Answers
+ 4
for (int i = 0; i < 10; i++) {
System.out.print("15 10 ");
}
Will do it 10 times
while (true) {
System.out.print("15 10 ");
}
To do it infinitely
+ 1
More generally if you want to switch between doing two different tasks you can use a boolean value like shown below
boolean flip = true;
while (condition){
if (flip)
//execute task 1
else
//execute task 2
flip = !flip;
}