Topic: 请求帮助(打印* * * * *)

  Print this page

1.请求帮助(打印* * * * *) Copy to clipboard
Posted by: keetty
Posted on: 2007-03-26 20:44

我是刚刚开始学习Java,想请教高手一个简单问题:
如何实现:

* * * * *
* * * * *
* * * * *
* * * * *

这样的打印啊,请高手帮忙啊!

2.Re:请求帮助 [Re: keetty] Copy to clipboard
Posted by: Devil2012
Posted on: 2007-03-27 07:30

试一下:
  System.out.println("\052\052\052\052\052");
  System.out.println("\052\052\052\052\052");
  System.out.println("\052\052\052\052\052");
  System.out.println("\052\052\052\052\052");

3.Re:请求帮助 [Re: keetty] Copy to clipboard
Posted by: aaarong
Posted on: 2007-03-27 18:21

public class Test2
{  public static void main(String[] args)
  {  String[][] str=new String[5][5];
    for(int i=0;i<str.length;i++)
    {  for(int j=0;j<str.length;j++)
      {  str[i][j]="* ";
      }
    }
    for(int i=0;i<str.length;i++)
    {  for(int j=0;j<str.length;j++)
      System.out.print(str[i][j]);
      System.out.println();
    }
  }
}

4.Re:请求帮助 [Re: aaarong] Copy to clipboard
Posted by: JiafanZhou
Posted on: 2007-03-28 02:59

aaarong wrote:
public class Test2
{ public static void main(String[] args)
{ String[][] str=new String[5][5];
for(int i=0;i<str.length;i++)
{ for(int j=0;j<str.length;j++)
{ str[i][j]="* ";
}
}
for(int i=0;i<str.length;i++)
{ for(int j=0;j<str.length;j++)
System.out.print(str[i][j]);
System.out.println();
}
}
}

Your implementation is too slow. Two completely redundant iterations. Now think about the following:

public class Test2
{ public static void main(String[] args)
{ String[][] str=new String[5][5];
for(int i=0;i<str.length;i++)
{ for(int j=0;j<str.length;j++)
{ str[i][j]="* ";
System.out.println(str[i][j]);
}
}
}

Or just simply print out the * without assign values to the 2-D array.

public class Test2
{ public static void main(String[] args)
{
for(int i=0;i<5;i++)
{ for(int j=0;j<5;j++)
System.out.println(str[i][j]);
}
}

If let me develop the code, see the following:

public class Dummy
{
public static void main(String[] args)
{
System.out.println("*****\n*****\n*****\n*****\n*****");
}
}


xixi...

Regards,
Jiafan

5.Re:请求帮助 [Re: HenryShanley] Copy to clipboard
Posted by: cxp108
Posted on: 2007-03-28 11:17

HenryShanley wrote:


public class Dummy
{
public static void main(String[] args)
{
System.out.println("*****\n*****\n*****\n*****\n*****");
}
}


xixi...

Regards,
Jiafan

哈哈
真没技术含量Big SmileBig SmileBig Smile

6.Re:请求帮助 [Re: keetty] Copy to clipboard
Posted by: xuxiaolei
Posted on: 2007-03-28 11:53

你们写的太麻烦了!看我写的:

for(int i = 1; i <= 20; i++)
   {
     System.out.print("* ");
     if(i % 5 == 0)
     {
       System.out.println();
     }
     
   }

7.Re:请求帮助 [Re: keetty] Copy to clipboard
Posted by: kwm0707
Posted on: 2007-03-28 14:54

xuxiaolei写的这个还象个程序员写的程序

使用更多技术,不一定能写出更好的代码来

一个目前非常流行的问题,请用最简单的方法算 2乘以8得多少?

8.Re:请求帮助 [Re: keetty] Copy to clipboard
Posted by: xuxiaolei
Posted on: 2007-03-28 16:31

楼上的好眼力啊,可惜我不是程序员,我目前做的是黑盒测试,程序员是我的梦想

你说的2 * 8 ,把2 用左移符号移3位,因为8等于2的3次方,这样的效率是最高的

9.Re:请求帮助 [Re: keetty] Copy to clipboard
Posted by: kwm0707
Posted on: 2007-03-28 16:43

答对 就是 2<<3

希望楼上梦想成真!

10.Re:请求帮助 [Re: keetty] Copy to clipboard
Posted by: aaarong
Posted on: 2007-03-28 17:36

受教了 使用更多技术,不一定能写出更好的代码来
谢谢。。。。。。

11.Re:请求帮助(打印* * * * *) [Re: keetty] Copy to clipboard
Posted by: xuxiaolei
Posted on: 2007-03-28 18:15

for(int i = 1; i <= 20; i++)
   {
   System.out.print("* ");
   if(i % 5 == 0)
   {
   System.out.println();
  
   for(int j = 1; j <= i / 5 * 3; j++)
     {
        System.out.print(" ");
     }
   }
  
   }

怎么一会时间,楼主的帖子就换了,所以我把程序修改了一下

12.Re:请求帮助(打印* * * * *) [Re: keetty] Copy to clipboard
Posted by: cxp108
Posted on: 2007-03-29 18:01

晕....
我说HenryShanley的答案"没有技术含量"那是开玩笑的!

如果需求仅是LZ说的描述的那样的话

public class Dummy
{
public static void main(String[] args)
{
System.out.println("*****\n*****\n*****\n*****\n*****");
}
}

是最佳答案,别把事情复杂化!
简单就是美!

13.Re:请求帮助(打印* * * * *) [Re: keetty] Copy to clipboard
Posted by: why
Posted on: 2007-03-31 08:00

請看清楚原題目, 要求的是

* * * * *
* * * * *
* * * * *
* * * * *

14.Re:请求帮助(打印* * * * *) [Re: keetty] Copy to clipboard
Posted by: xuxiaolei
Posted on: 2007-04-01 13:18

why 是楼主把帖子换了,本来不是这样的

*****
*****
*****
*****

15.Re:请求帮助(打印* * * * *) [Re: keetty] Copy to clipboard
Posted by: 书记
Posted on: 2007-04-02 18:29

俺是菜年,俺这么写
public class WanXingXing
{
  public static void main(String args[])
  {
    for(int i=1;i<5;i++)
    {
      for(int j=1;j<i;j++)
      {
        System.out.print(" ");
      }
      for(int j=0;j<5;j++)
      {
        System.out.print("* ");
      }
      System.out.println();
    }
  }
}

16.Re:请求帮助(打印* * * * *) [Re: 书记] Copy to clipboard
Posted by: zjx850617
Posted on: 2008-01-27 15:42

你果然是菜鸟 一只哇,你那样只能输入
*
*
*
*
*

17.Re:请求帮助(打印* * * * *) [Re: keetty] Copy to clipboard
Posted by: liuqianqian
Posted on: 2008-01-28 20:36

public static void main(String [] args){
for(int m=1;m<=5;m++){
    for(int n=1;n<m;n++){
      System.out.print(" ");
      
    }
    System.out.println("*****");
}

还是写简单一点好,比较好理解!

18.Re:请求帮助(打印* * * * *) [Re: keetty] Copy to clipboard
Posted by: Joffeec
Posted on: 2008-06-29 15:00

哈哈。。太有趣了。。我也来。。。

public class Stars {
  public static void main(String[] args ) {
   String stars = "* * * * *";
   for( int i = 0 ; i < 4 ; i ++ ){
      for( int j = 0 ; j < (i * 3 + 1) ; j ++ ) {
        System.out.print(" ");
      }
      System.out.println(stars);
   }
  
  }
}


   Powered by Jute Powerful Forum® Version Jute 1.5.6 Ent
Copyright © 2002-2021 Cjsdn Team. All Righits Reserved. 闽ICP备05005120号-1
客服电话 18559299278    客服信箱 714923@qq.com    客服QQ 714923