本帖最后由 lzh2015 于 2015-4-21 19:52 编辑
需求: 1 目前刚上视频入学班,今有同学问我这个有没有什么好想法,刚学比较捉,
2 1 2 打了一个很复杂的代码,一看有很多可以改进的地方,
3 2 1 2 3 先发上来大家玩玩,后面有改进的话入入续续改进。
4 3 2 1 2 3 4
5 4 3 2 1 2 3 4 5
class JinDemo
{
public static void main(String[] args)
{
for (int a=1;a<=9 ;a+=2 )
{
for (int b=a;b<=9 ;b++ )
{
System.out.print(" ");
}
switch (a)
{
case 1 :
System.out.println(a);
break;
case 3:
a-=1;
System.out.println(a+" "+(a-1)+" "+a);
a+=1;
break;
case 5:
a-=2;
System.out.println(a+" "+(a-1)+" "+(a-2)+" "+(a-1)+" "+a);
a+=2;
break;
case 7:
a-=3;
System.out.println(a+" "+(a-1)+" "+(a-2)+" "+(a-3)+" "+(a-2)+" "+(a-1)+" "+a);
a+=3;
break;
case 9:
a-=4;
System.out.println(a+" "+(a-1)+" "+(a-2)+" "+(a-3)+" "+(a-4)+" "+(a-3)+" "+(a-2)+" "+(a-1)+" "+a);
a+=4;
break;
default:
}
}
}
}
|