不就是转码 2022-07-06 20:26 采纳率: 100%
浏览 23
已结题

boyException in thread "main" java.util.IllegalFormatConversionException: d != Linkedlist.Boy

问题:
boyException in thread "main" java.util.IllegalFormatConversionException: d != Linkedlist.Boy
at java.base/java.util.Formatter$FormatSpecifier.failConversion(Formatter.java:4426)
at java.base/java.util.Formatter$FormatSpecifier.printInteger(Formatter.java:2938)
at java.base/java.util.Formatter$FormatSpecifier.print(Formatter.java:2892)
at java.base/java.util.Formatter.format(Formatter.java:2673)
at java.base/java.io.PrintStream.format(PrintStream.java:1053)
at java.base/java.io.PrintStream.printf(PrintStream.java:949)
at Linkedlist.CircleSingleLinkedList.countBoy(Joseph.java:86)
at Linkedlist.Joseph.main(Joseph.java:10)

为什么老是跑出异常?TT


```java
    public void showBoy() {
        if (first == null) {
            System.out.println("there is no boy!");
            return;
        }
        Boy curBoy = first;
        while (true) {
            System.out.printf("the boy's No is %d \n", curBoy.getNo());
            if (curBoy.getNext() == first) { //get the last No ,the traverse is finished
                break;
            }
            curBoy = curBoy.getNext();//move it
        }
    }

public void countBoy(int startNo, int count, int num) {
    if (first == null || startNo < 1 || startNo > num) {
        System.out.println("the parameters is wrong,please enter it again");
        return;
    }
    Boy helper = first;//创建一个辅助指针,帮小孩出圈
    while (true) {
        if (helper.getNext() == first) {//事先让helper指向最后一个节点
            break;
        }
        helper = helper.getNext();
    }
    //小孩报数前,先让first和helper移动 k-1 次
    for (int j = 0; j < startNo - 1; j++) {
        first = first.getNext();
        helper = helper.getNext();
    }
    //当小孩报数时,first和helper同时移动 m-1 次,然后出圈
    //因为这里是一个循环操作,直到圈中只有一个节点
    while (true) {
        if (helper == first) {//only one node
            break;
        }
        for (int j = 0; j < count - 1; j++) {//move (k - 1) node
            first = first.getNext();
            helper = helper.getNext();
        }
        System.out.printf("boy %d should go out \n", first.getNext());
        first = first.getNext();
        helper.setNext(first);//helper的指针域指向first 形成一个新环
    }
    System.out.printf("the last boy left in the CLL is %d \n", helper.getNext());


}

```

  • 写回答

0条回答 默认 最新

    报告相同问题?

    问题事件

    • 系统已结题 7月14日
    • 修改了问题 7月6日
    • 创建了问题 7月6日

    悬赏问题

    • ¥15 rt-thread线程切换的问题
    • ¥20 python忆阻器数字识别
    • ¥15 无法输出helloworld
    • ¥15 高通uboot 打印ubi init err 22
    • ¥20 PDF元数据中的XMP媒体管理属性
    • ¥15 R语言中lasso回归报错
    • ¥15 网站突然不能访问了,上午还好好的
    • ¥15 有没有dl可以帮弄”我去图书馆”秒选道具和积分
    • ¥15 semrush,SEO,内嵌网站,api
    • ¥15 Stata:为什么reghdfe后的因变量没有被发现识别啊