Spinning rod animation/Text: Difference between revisions

Content deleted Content added
PureFox (talk | contribs)
Added Kotlin
PureFox (talk | contribs)
Added Java
Line 106: Line 106:
}
}
fmt.Print("\033[?25h") // restore the cursor
fmt.Print("\033[?25h") // restore the cursor
}</lang>

=={{header|Java}}==
{{trans|Go}}
<lang java>public class SpinningRod
{
public static void main(String[] args) throws InterruptedException {
String a = "|/-\\";
System.out.print("\033[2J"); // hide the cursor
long start = System.currentTimeMillis();
while (true) {
for (int i = 0; i < 4; i++) {
System.out.print("\033[2J"); // clear terminal
System.out.print("\033[0;0H"); // place cursor at top left corner
for (int j = 0; j < 80; j++) { // 80 character terminal width, say
System.out.print(a.charAt(i));
}
Thread.sleep(250);
}
long now = System.currentTimeMillis();
// stop after 20 seconds, say
if (now - start >= 20000) break;
}
System.out.print("\033[?25h"); // restore the cursor
}
}</lang>
}</lang>