摩托罗拉的面试题(50分送上,本人已做出,希望各位高手请教请教)
但请在此贴http://community.csdn.net/Expert/topic/4312/4312301.xml?temp=4.470462E-02里回复,,因为小弟此贴没有人能给我满意的答复,所以把这50分放在能回答"摩托罗拉的面试题(50分送上,本人已做出,希望各位高手请教请教)
"这个问题上.
但请在此贴http://community.csdn.net/Expert/topic/4312/4312301.xml?temp=4.470462E-02里回复,,因为小弟此贴没有人能给我满意的答复,所以把这50分放在能回答"摩托罗拉的面试题(50分送上,本人已做出,希望各位高手请教请教)
"这个问题上.
但我不熟C++,只能用JAVA做了。
题目是:
1.打印如下图案,共19行,只能有一个for外层循环
*
***
*****
*******
*********
***********
*************
***************
*****************
*******************
*****************
***************
*************
***********
*********
*******
*****
***
*
请到
http://community.csdn.net/Expert/topic/4312/4312301.xml?temp=4.470462E-02里回复,,因为小弟此贴没有人能给我满意的答复,所以把这帖的50分放在能回答"摩托罗拉的面试题"这个问题上.希望大家见凉哦。
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);
}
}
}
}
}
{
#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");
}
}
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 );
}
}