0

我试图添加一些小动画,但只有当用户想要看到它们时。当我这样写时,我不断收到一个非法的表达式开始错误。为什么是这样?我是 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);
    }

}
4

2 回答 2

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);
        }

    }
}
于 2013-09-13T16:08:46.127 回答
0

删除此行

if ( fxAnswer .equalsIgnoreCase("Yes") )
于 2013-09-13T15:49:36.397 回答