首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > J2SE开发 >

一个面试题,求解解决方法

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

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

[解决办法]
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( " ");
}
}
}

热点排行