我正在尝试添加一些小动画,但仅在用户想要看到它们时才添加。当我像这样写它时,我一直得到一个非法的表达错误开始。为什么是这样?我是Java的新手,到目前为止我对它有很多乐趣,但我似乎无法找到解决这个问题的方法。
我猜你不能拥有public static void main( String[] args ) throws Exception
我一直收到以下错误:ureported exception InterruptedException; must be caught or declared to be thrown
if ( fxAnswer .equalsIgnoreCase("Yes") )
public static void main( String[] args ) throws Exception
{
int repeats = 5;
int steps_per_second = 10;
for ( int i=0; i<repeats*22 ; i++ )
{
if ( i%22 == 0 )
System.out.print(" ...SPECIAL EFFECTS!! \r");
else if ( i%22 == 1 )
System.out.print(" ...SPECIAL EFFECTS! \r");
else if ( i%22 == 2 )
System.out.print(" !...SPECIAL EFFECTS \r");
else if ( i%22 == 3 )
System.out.print(" !!...SPECIAL EFFECT \r");
else if ( i%22 == 4 )
System.out.print(" S!!...SPECIAL EFFEC \r");
else if ( i%22 == 5 )
System.out.print(" TS!!...SPECIAL EFFE \r");
else if ( i%22 == 6 )
System.out.print(" TS!!...SPECIAL EFFE \r");
else if ( i%22 == 7 )
System.out.print(" CTS!!...SPECIAL EFF \r");
else if ( i%22 == 8 )
System.out.print(" ECTS!!...SPECIAL EF \r");
else if ( i%22 == 9 )
System.out.print(" FECTS!!...SPECIAL EF \r");
else if ( i%22 == 10 )
System.out.print(" FECTS!!...SPECIAL E \r");
else if ( i%22 == 11 )
System.out.print(" FFECTS!!...SPECIAL \r");
else if ( i%22 == 12 )
System.out.print(" EFFECTS!!...SPECIAL \r");
else if ( i%22 == 13 )
System.out.print(" EFFECTS!!...SPECIA \r");
else if ( i%22 == 14 )
System.out.print(" L EFFECTS!!...SPECI \r");
else if ( i%22 == 15 )
System.out.print(" AL EFFECTS!!...SPEC \r");
else if ( i%22 == 16 )
System.out.print(" IAL EFFECTS!!...SPE \r");
else if ( i%22 == 17 )
System.out.print(" CIAL EFFECTS!!...SP \r");
else if ( i%22 == 18 )
System.out.print(" ECIAL EFFECTS!!...S \r");
else if ( i%22 == 19 )
System.out.print(" PECIAL EFFECTS!!... \r");
else if ( i%22 == 20 )
System.out.print(" SPECIAL EFFECTS!!.. \r");
else if ( i%22 == 21 )
System.out.print(" .SPECIAL EFFECTS!!. \r");
else if ( i%22 == 22 )
System.out.print(" ..SPECIAL EFFECTS!! \r");
else if ( i%22 == 23 )
System.out.print(" ...SPECIAL EFFECTS!! \r");
Thread.sleep(1000/ steps_per_second);
}
}
答案 0 :(得分:1)
有一种更简单的方法:
public class StringEFFECTS {
public static String rotateString(String s, int steps) {
return s.substring(steps) + s.substring(0, steps);
}
public static void main(String[] args) throws Exception
{
String str = " ...String EFFECTS!! ";
for (int i = 0; i < 100; i++) {
System.out.print(str);
str = StringEFFECTS.rotateString(str, 2);
System.out.print("\r");
Thread.sleep(33);
}
}
}
答案 1 :(得分:0)
删除此行
if ( fxAnswer .equalsIgnoreCase("Yes") )