JAVA:我这样打出来的代码输出的为什么不是矩形呢???

来源:百度知道 编辑:UC知道 时间:2024/06/28 07:48:04
public class lesson2
{
public static void main(String [] args)
{

dramtemple(3,5);
dramtemple(2,4);
dramtemple(6,10);

}

static void dramtemple(int x,int y)
{
for(int i=0;i<x;i++)
{
for(int j=0;j<y;j++)

{System.out.print('*'); }
}
System.out.println(); }

}

输出*以后换行的地方错了
package chapter4;

public class lesson2 {
public static void main(String[] args) {

dramtemple(3, 5);
dramtemple(2, 4);
dramtemple(6, 10);

}

static void dramtemple(int x, int y) {
for (int i = 0; i < x; i++) {
for (int j = 0; j < y; j++)

{
System.out.print('*');
}
System.out.println();//就是这儿想要矩形这个换行是必须的
}
System.out.println();//这个换行可要可不要
}

}

以后注意格式,否则容易出这种错误。eclipse里ctrl+shift+f自动排版

public static void main(String[] args) {

dramtemple(3, 5);
dramtemple(2, 4);
dramtemple(6, 10);

}

static void dramtemple(int x, int y) {
for (int i = 0; i < x; i++) {
for (int j = 0; j < y; j++)

{
System.out.print('*');
}
System.out.println();//这个地方写错地方了
}

}
你以后写的时候