Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/loops/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Loops 我的程序循环赢了';t发送并给出正确的输出_Loops_Output - Fatal编程技术网

Loops 我的程序循环赢了';t发送并给出正确的输出

Loops 我的程序循环赢了';t发送并给出正确的输出,loops,output,Loops,Output,我试图创建一个循环,找出“MP”比“AP”高需要多长时间。然而,当我开始这个项目时,它告诉我“墨西哥的人口将在121年内超过。”直到我强制结束这个项目。你知道我哪里出错了吗 public class Population { public static void main(String args[]) { int Mexico = 121; int America = 315; int MYear = (101/100);

我试图创建一个循环,找出“MP”比“AP”高需要多长时间。然而,当我开始这个项目时,它告诉我“墨西哥的人口将在121年内超过。”直到我强制结束这个项目。你知道我哪里出错了吗

public class Population
{ 
    public static void main(String args[]) 
    { 
        int Mexico = 121;
        int America = 315;
        int MYear = (101/100); 
        int AYear = (15/100);
        int MP = (Mexico * MYear);
        int AP = (America * MYear);
        while (MP <= AP) 
        { 
            System.out.println("Mexico's population will exceed in " + MP + "Years."); 

        } 
    } 
}
公共类人口
{ 
公共静态void main(字符串参数[])
{ 
int墨西哥=121;
国际美洲=315;
int-MYear=(101/100);
整年=(15/100);
int MP=(墨西哥*迈耶);
int AP=(美国*迈尔);

虽然(MP您没有更改循环中的任何值,为什么希望它停止?您的意思是什么?抱歉,我仍在学习如何编码。我不明白您的意思。我如何使其值更改?@CorruptedWizard您需要更新循环中
MP
AP
的值。否则,变量将被有效地统计ic.
int-MP=(Mexico*MYear)
在循环中每次都将值设置为该值;无论是
Mexico
还是
MYear
都不会更改,因此
MP
永远不会更改。我该怎么做?