Java 一条信息,上面写着;“混淆缩进”;及;将返回值赋给新变量";
我一直在做这个项目,项目运行良好,但它显示了“混淆缩进”和“将返回值赋给新变量”警告,我不知道这是怎么回事。这是带有警告的行: System.out.printf(“平方和:%.0f\n”,tsquee)强> 以下是完整的项目。谢谢Java 一条信息,上面写着;“混淆缩进”;及;将返回值赋给新变量";,java,return,indentation,Java,Return,Indentation,我一直在做这个项目,项目运行良好,但它显示了“混淆缩进”和“将返回值赋给新变量”警告,我不知道这是怎么回事。这是带有警告的行: System.out.printf(“平方和:%.0f\n”,tsquee) 以下是完整的项目。谢谢 double n = 0; while (n < 25) { n = n + 1; if (n > 25) break; System.out.printf(
double n = 0;
while (n < 25)
{
n = n + 1;
if (n > 25)
break;
System.out.printf("%3.0f%15.2f%16.2f%17.2f%15.2f\n", n, Math.cbrt(n), Math.sqrt(n), Math.pow(n, 3), Math.pow(n, 2));
}
{
double tsquee = 0.0, tsqueer = 0.0;
int csq = 0, ccube = 0;
for (n = 0; n <= 25; n++)
tsquee += Math.pow(n, 2); tsqueer += Math.sqrt(n);
for (n = 0; n <= 25; n++)
if (Math.pow(n, 2) > 250)
{
csq++;
}
else if (Math.pow(n, 3) > 2000)
{
ccube++;
}
System.out.printf("The sum of the squares: %.0f\n", tsquee);
System.out.printf("The sum of the square roots: %.2f\n", tsqueer);
System.out.println("The number of squares greater than 250: " + csq);
System.out.println("The number of cubes greater than 2000: " + ccube);
}
}
double n=0;
而(n<25)
{
n=n+1;
如果(n>25)
打破
System.out.printf(“%3.0f%15.2f%16.2f%17.2f%15.2f\n”,n,Math.cbrt(n),Math.sqrt(n),Math.pow(n,3),Math.pow(n,2));
}
{
双Tsquer=0.0,Tsquer=0.0;
int csq=0,ccube=0;
对于(n=0;n 2000)
{
ccube++;
}
System.out.printf(“平方和:%.0f\n”,tsquee);
System.out.printf(“平方根之和:%.2f\n”,tsqueer);
System.out.println(“大于250的方块数:“+csq”);
System.out.println(“大于2000的立方体数:+ccube”);
}
}
Kay之所以出现“令人困惑的缩进”警告,可能是因为不需要在while循环之后开始并一直到末尾的一组大括号。此外,for循环语法不正确。我想你想要的是:
for (n = 0; n <= 25; n++)
{
if (Math.pow(n, 2) > 250)
{
csq++;
}
else if (Math.pow(n, 3) > 2000)
{
ccube++;
}
}
for(n=0;n 250)
{
csq++;
}
else if(数学功率(n,3)>2000)
{
ccube++;
}
}
但我不确定。您需要将要循环的代码括在花括号内,就像您在while循环中所做的那样
此外,由于两个for循环具有相同的边界和条件,因此可以将它们组合为一个for循环:
for (n = 0; n <= 25; n++)
{
tsquee += Math.pow(n, 2);
tsqueer += Math.sqrt(n); // I would also put these on separate lines
if (Math.pow(n, 2) > 250)
{
csq++;
}
else if (Math.pow(n, 3) > 2000)
{
ccube++;
}
}
for(n=0;n 250)
{
csq++;
}
else if(数学功率(n,3)>2000)
{
ccube++;
}
}
警告非常具体。您的缩进非常令人困惑——例如,查看for
中的if/else
。它看起来是在同一级别上的,因此出现在for
之后,而不是在内部。无论何时使用for
,while
,do
,if
或else
,都最好使用{/code>和
。省略它们可能会导致错误。我认为每一个Java程序员都在某个时候掉进了这个陷阱。