Loops 在编写一个程序以了解这么多人中谁是最年长的人时,是否有公式I';我失踪了?

Loops 在编写一个程序以了解这么多人中谁是最年长的人时,是否有公式I';我失踪了?,loops,Loops,不断出现“[name]是年龄最大的0岁” 我使用for循环是因为我有一个关于循环的考试,它只是为了学习 非常感谢您的回答 康纳 System.out.println(“涉及多少人?”); amount=EasyIn.getInt(); currentage=0; 对于(指数=1;指数年龄) { 当前年龄=年龄; maxname=名称; 最大年龄=年龄; } System.out.println(“最年长的人是“+maxname+”,年龄为“+``maxage+”岁”); } var curre

不断出现“[name]是年龄最大的0岁” 我使用for循环是因为我有一个关于循环的考试,它只是为了学习

非常感谢您的回答

康纳

System.out.println(“涉及多少人?”);
amount=EasyIn.getInt();
currentage=0;
对于(指数=1;指数年龄)
{
当前年龄=年龄;
maxname=名称;
最大年龄=年龄;
}
System.out.println(“最年长的人是“+maxname+”,年龄为“+``maxage+”岁”);
}

var currentage从未重新定义,因此您的if();语句永远不会启动。

您的>应该if(currentage>age)。如果年龄更高,您希望更改当前年龄,而不是相反。

是的,如果不查看您的代码,我们将无法帮助您。
    System.out.println("How many people are involved?");
    amount = EasyIn.getInt();

    currentage = 0;

    for(index = 1; index <= amount; index++)
    {

        System.out.println("Enter the name of " + index + " person");
        name = EasyIn.getString();

        System.out.println();

        System.out.println("Enter their age please ");
        age = EasyIn.getInt();

        System.out.println();


    if(currentage > age)
        {
            currentage = age;
            maxname = name;
            maxage = age;
        }


    System.out.println("The oldest person is " + maxname + "with the age of " + `               `maxage + " years");

    }
currentage=0
if(currentage > age){
    do stuff;
}