sinat_34458693 2016-04-03 14:08 采纳率: 0%
浏览 1409
已采纳

java se IllegalFormateConverssionException

public class TestScoreClass {
public static final int NUM = 30;
public static void main(String[] args){
ScoreClass[] score = new ScoreClass[NUM];
enterScore(score);
sort(score);
printScore(score);

}


public static void enterScore(ScoreClass[] score){
    for(int i = 0; i < score.length; i++){
        score[i] = new ScoreClass(1000+i,(int)(Math.random()*100));

    }
}
public static void printScore(ScoreClass[] score){
    for(int i=0; i < score.length;i++){
        System.out.printf("%4d",score[i]);
    }
}
public static void sort(ScoreClass[] score){
    int index;
    for(int i = 0;i < score.length-1;i++){
        index = i;
        for(int j = i+1;j < score.length; j++){
            if(score[j].getScore() > score[index].getScore()){
                index = j;
            }
            if(index!=i){
                ScoreClass s = score[i];
                score[i] = score[index];
                score[index] = s;
            }
        }
    }
}

}

控制台:

Exception in thread "main" java.util.IllegalFormatConversionException: d != ScoreClass
at java.util.Formatter$FormatSpecifier.failConversion(Formatter.java:3992)
at java.util.Formatter$FormatSpecifier.printInteger(Formatter.java:2708)
at java.util.Formatter$FormatSpecifier.print(Formatter.java:2660)
at java.util.Formatter.format(Formatter.java:2432)
at java.io.PrintStream.format(PrintStream.java:920)
at java.io.PrintStream.printf(PrintStream.java:821)
at TestScoreClass.printScore(TestScoreClass.java:21)
at TestScoreClass.main(TestScoreClass.java:8)

  • 写回答

2条回答 默认 最新

  • threenewbee 2016-04-03 14:15
    关注

    System.out.printf("%4d",score[i]);
    这是Java,不是C,什么%4d

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 无源定位系统的时差估计误差标准差
  • ¥15 请问这个代码哪里有问题啊
  • ¥20 python--version在命令端输入结果Python is not defined怎么办?还有pip不是exe格式是不是没安装成功?
  • ¥15 通过GaussianView进行结构微调消除虚频
  • ¥15 调用transformers库
  • ¥15 由于导出的数据名字中带有/,导致Matlab打不开,怎么办?
  • ¥15 新硬盘安装的程序总是崩溃,提示遇到错误
  • ¥15 openpcdet自制数据集评估bev精度和3d精度相同
  • ¥15 excel 上下按钮 显示行
  • ¥20 云卓h12pro 数传问题