java问题。会的决绝下
来源:百度知道 编辑:UC知道 时间:2024/05/19 05:30:39
没给数组的情况下 怎么才能打出下面的 数字?
1
23
345
4567
56789
1
23
345
4567
56789
给你参考一下,
public class No{
public static void main(String[] args){
for(int i=1;i<=5;i++){
for(int j=i;j<i+i;j++){
System.out.print(j);
}
System.out.println();
}
}
}
楼上两种写法真好,虽然实现上是一样的,概念不一样
public class a{
public a(){}
void a()
{
for(int i=1;i<6;i++)
{
for(int j=i;j<i+i;j++)
{
System.out.print(j+" ");
}
System.out.println();
}
}
public static void main(String args[])
{
new a().a();
}
}
改写一点点
public class a{
public a()
{
for(int i=1;i<6;i++)
{
for(int j=i;j<i+i;j++)
{
System.out.print(j+" ");
}
System.out.println();
}
}
public static void main(String args[])
{
new a();
}
}
用的循环..