摩托罗拉的面试题(50分送上,本人已做出,希望各位高手请教请教)
但请在此贴http://community.csdn.net/Expert/topic/4312/4312301.xml?temp=4.470462E-02里回复,,因为小弟此贴没有人能给我满意的答复,所以把这50分放在能回答"摩托罗拉的面试题(50分送上,本人已做出,希望各位高手请教请教)
"这个问题上.

解决方案 »

  1.   

    原本是C++的一个贴子的.
    但我不熟C++,只能用JAVA做了。
    题目是:
      1.打印如下图案,共19行,只能有一个for外层循环
             *         
            ***        
           *****       
          *******      
         *********     
        ***********
       *************   
      ***************  
     ***************** 
    *******************
     ***************** 
      ***************  
       *************   
        ***********    
         *********     
          *******      
           *****       
            ***        
             *
      

  2.   

    注意:
      请到
       http://community.csdn.net/Expert/topic/4312/4312301.xml?temp=4.470462E-02里回复,,因为小弟此贴没有人能给我满意的答复,所以把这帖的50分放在能回答"摩托罗拉的面试题"这个问题上.希望大家见凉哦。
      

  3.   

    小弟的答案是:
       public class TestFor{
    public static void main(String [] args){
    //char [] a = new char[19];
    for(int i = 0 ; i<19 ; i++){
    if(i<10){
    char [] a = new char[19];
    //这样也行
        /*
    for(int j = 0 ; j < 2*i+1; j++){
    int temp = (19-(2*i+1))/2;
    a[temp+j] = '*';
    }
    */
    for(int j = 18/2-i ; j <= 18/2+i ; j++){
    a[j] = '*';
    }
    System.out.println(a);
    }else{
    char [] b = new char[19];
    for(int j = i%10+1 ; j < 18-i%10 ; j++){
        b[j] = '*';
        }
        System.out.println(b);
    }
    }
    }
    }
      

  4.   

    不用循环写19个printf也可以呀
      

  5.   

    for (int i = 1; i <= 19; i++) {  int starNum = 19 - 取绝对值((i-10))*2  //画
    }
      

  6.   

    我可以打印出来,不过方法比较笨拙,请大家指点void PrintStar()
    {
    #define LineNum 19

    int nStarNum=0;
    int nSpaceNum=0;
    for(int n=1;n<=LineNum;n++)
    {
    nStarNum = LineNum - abs(2*(n-10));
    nSpaceNum = abs(n-10);
    char star[20] = "*******************";
    char space[10] = "         "; char strStart[20];
    star[nStarNum] = 0;
    strcpy(strStart, star); char strSpace[20];
    space[nSpaceNum] = 0;
    strcpy(strSpace, space); char str[20];
    strcat(strSpace, strStart);
    strcpy(str, strSpace); printf(str);
    printf("\n");
    }
    }
      

  7.   

    我的答案:
    public static void printDiamond( int cnt)
    {
    StringBuffer s=new StringBuffer(cnt*2);
    s.setLength( cnt*2 );
    for( int i=1; i<=cnt*2-1; i++)
    {
    int j=0;
    if( i<=cnt)
    for( j=0; j<cnt-i; j++) s.setCharAt( j, ' ');
    else
    for( j=0; j<i-cnt; j++) s.setCharAt( j, ' ');

    for( int k=j; j< cnt*2-k; ){
    s.setCharAt( j++, '*');
    s.setCharAt( j++, ' ');
    } System.out.println( s );
    }
    }