java数字图案打印问题
我正在尝试使用java创建一个模式,它看起来像下图。有人能帮我纠正一下吗?告诉我我的代码出了什么问题 试试这个:java数字图案打印问题,java,Java,我正在尝试使用java创建一个模式,它看起来像下图。有人能帮我纠正一下吗?告诉我我的代码出了什么问题 试试这个: package welcome; import java.util.Scanner; public class Welcome { public static void main(String args[]) { Scanner sc= new Scanner(System.in); System.out.println("enter the rows
package welcome;
import java.util.Scanner;
public class Welcome
{
public static void main(String args[])
{
Scanner sc= new Scanner(System.in);
System.out.println("enter the rows");
int rows= sc.nextInt();
System.out.println("here is the pattern");
int i, j, k=1;
String tmp="";
for(i=1; i<=rows; i++)
{
for(j=1; j<=k; j++)
{
tmp = tmp + "*";
}
k = k + 2;
System.out.println(tmp+ j +"\n");
tmp = "";
}
}
}
套餐欢迎;
导入java.util.Scanner;
公开课欢迎
{
公共静态void main(字符串参数[])
{
扫描仪sc=新的扫描仪(System.in);
System.out.println(“输入行”);
int rows=sc.nextInt();
System.out.println(“这是模式”);
int i,j,k=1;
字符串tmp=“”;
对于(i=1;i您的调试尝试向您展示了什么?这个问题不是一个真正的问题。请尝试用您尝试过的内容和尝试时发生的情况来重新表述它。询问有关某件事情的特定问题(例如,为什么此for循环的效果不如预期?)最后,如果你正在寻找一种更好的方法来编写已经运行的代码,你可能需要访问姐妹站点代码审阅。不要在你的内部循环中打印j。你的老师可能希望你学习递归。要打印以N行开始和结束的模式,请打印从1到N的数字,或者递归打印模式星以N+2行结束,然后再次打印从1到N的数字。
* 1
* 1* 2* 3
* 1* 2* 3* 4* 5
* 1* 2* 3* 4* 5* 6* 7
* 1* 2* 3* 4* 5* 6* 7* 8* 9
package welcome;
import java.util.Scanner;
public class Welcome
{
public static void main(String args[])
{
Scanner sc= new Scanner(System.in);
System.out.println("enter the rows");
int rows= sc.nextInt();
System.out.println("here is the pattern");
int i, j, k=1;
String tmp="";
for(i=1; i<=rows; i++)
{
for(j=1; j<=k; j++)
{
tmp = tmp + "*";
}
k = k + 2;
System.out.println(tmp+ j +"\n");
tmp = "";
}
}
}