UnknownFormatConversionException

时间:2014-12-08 12:36:24

标签: java

我有一个关于studentPoll代码的作业。它没有工作,我总是得到UnknownFormatConversionException.任何想法?日Thnx

public class studentPoll {
 {
     public static void main( String[]args)
     {
        int[] responses = { 1, 2 , 5, 4, 3 , 5, 2, 1 , 3, 3, 1, 4, 3, 3, 3,
           2, 3, 3, 2, 14 };

        int [ ] frequency = new int [ 6 ];

        for ( int answer = 0; answer <responses.length; answer++ )
        {
            try
            {
                ++ frequency [responses[answer] ];
            } 
            catch ( ArrayIndexOutOfBoundsException e )
            {
                System.out.println( e );
                System.out.printf( "responses[ %d] = %d\n\n",answer, responses[answer] );
            }
        } 

        System.out.printf( " %s%1 0s\n", "Rating", " Frequency " );

        for ( int rating = 1; rating < frequency.length; rating ++ )
           System.out.printf( "% 6d%10 d\n" , rating, frequency[ rating ] ) ;
        } 
} 

1 个答案:

答案 0 :(得分:0)

将此部分"% 6d%10 d\n"更改为"%6d%10d\n"。你那里有不可接受的空间。

另外,将此部分" %s%1 0s\n"更改为"%s%s\n"。不确定你打算在那里做什么。