日期:2014-05-20  浏览次数:20866 次

一个面试题,求解
完成下列程序
*
*.*.  
*..*..*..  
*...*...*...*...  
*....*....*....*....*....
*.....*.....*.....*.....*.....*.....   *......*......*......*......*......*......*......
*.......*.......*.......*.......*.......*.......*.......*.......

------解决方案--------------------
public static void main(String[] args) {
for (int a = 1; a < 7; a++) {
for (int b = 0; b < a; b++) {
System.out.print( "* ");
for (int c = 1; c < a; c++) {
System.out.print( ". ");
}
}
System.out.println();
}
}
------解决方案--------------------
我也来写个,C#版的:
namespace ConsoleApplication6
{
class Program
{
static void Main(string[] args)
{
for (int i = 1; i < 7; i++)
{
for (int j = 0; j < i; j++)
{
Console.Write( "* ");
for (int k = 1; k < i; k++)
Console.Write( ". ");
}
Console.WriteLine();
}
}
}
}
------解决方案--------------------

public class Test5 {

public static void main(String[] args){

for(int i = 0; i < 7; i++){
if( i == 5){
for(int j = 0; j < 13; j++){
System.out.print( "* ");
for(int k = 0; k < i; k++)
System.out.print( ". ");
}
}
else{
for(int j = 0; j < i; j++){
System.out.print( "* ");
for(int k = 0; k < i; k++)
System.out.print( ". ");
}
}
System.out.println( " ");
}
}
}