我觉得我写的代码是错误的,但我不知道为什么。对我来说看起来很不专业。这些如何从一个到四个打印四行和四列数字并在达到四个后重新启动
/* 1234
2341
3412
4123
*/
public class pattern{
public static void main(String args[]){
for(i=1; i<=4; i++)
{for(j=1; j<=4; j++)
{System.out.print(i);
}
System.out.println();
while(i>4)
{ int i= 1;
i++;
System.out.print(i);}
System.out.println();
}
首先,这段代码是错误的。 'string'和'system'(小写's')都是类。 “我”和“J”从未被宣布。其次,这个代码是*可怕*格式。 –
你的while循环是无限循环。你正在初始化循环内的计数器 – Rehman
你的while循环是如何工作的?你的条件是我大于4,但是在循环内你把我初始化为1,然后加1,所以它变成2.此外,许多其他问题,例如大写错误,初始化循环变量失败,关闭不足大括号,错误的缩进...... – Foleosy