黑马程序员技术交流社区
标题:
点招题
[打印本页]
作者:
Last_indulge
时间:
2016-4-1 20:41
标题:
点招题
键盘接收一个整数,输出*,是几个就输出几个哈.15分钟以内搞定.10分钟以内满分
如:
键盘输入:2 就打印下列
*
* *
*
作者:
Last_indulge
时间:
2016-4-1 20:43
我自己思路如下(望大神改进):
public static void main(String[] args) {
//int count = 3;
Scanner sc = new Scanner(System.in);
System.out.println("请输入多少行的菱形*");
int count = sc.nextInt();
for(int i = 1;i<=count;i++){
for(int j =1; j<=i;j++){
if(j==1){
for (int j2 = 0; j2 < count-i; j2++) {
System.out.print(" ");
}
}
System.out.print("*"+" ");
}
System.out.println();
}
for(int x=count-1;x>=1;x--){
for(int y=x;y>=1;y--){
if(y==x){
for (int i = 0; i < count-x; i++) {
System.out.print(" ");
}
}
System.out.print("*"+" ");
}
System.out.println();
}
}
作者:
xuqinghua
时间:
2016-4-2 21:47
不错 加油
欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/)
黑马程序员IT技术论坛 X3.2