当前位置: 代码迷 >> Eclipse >> 求解打印正三角形有关问题
  详细解决方案

求解打印正三角形有关问题

热度:23   发布时间:2016-04-23 13:30:20.0
求解打印正三角形问题
public class sanjiaoxing {
public static void main(String[] args) {
int line = 5 ;
for (int x=0;x<5;x++);{
for (int y=0;y<5-x;y++);{
System.out.print(" ");
}
for (int y=0;y<=x;y++);{
System.out.print("* ");
}
System.out.println();
}
}

}

为什么会提示:x cannot be resolved to a variable


求解!

------解决方案--------------------
public class sanjiaoxing {
public static void main(String[] args) {
int x=0;
for (x=0;x<5;x++)
{
for (int y=0;y<5-x;y++)
{
System.out.print(" ");
}
for (int y=0;y<=x;y++)
{
System.out.print("* ");
}
System.out.println("");
}
}

}
------解决方案--------------------
for (int x=0;x<5;x++);{
这行不该有分号的,去掉就能运行,不过你程序不对
------解决方案--------------------
仔细看了下,你所有FOR语句后面都多加了个;,去掉对了的,记得给分啊
  相关解决方案