黑马程序员技术交流社区
标题:
求高手指教:利用程序输出如下图形
[打印本页]
作者:
王小丑
时间:
2013-1-29 19:02
标题:
求高手指教:利用程序输出如下图形
本帖最后由 张向辉 于 2013-2-2 12:08 编辑
今天看到一个题如下:利用程序输出如下图形
*
* * *
* * * * *
* * * * * * *
* * * * *
* * *
*
求高手指教 希望给出能运行的程序 谢谢
作者:
李挺
时间:
2013-1-29 20:31
class Day05
{
public static void main(String[] args)
{
for(int i=1;i<=4;i++)
{
for(int j=1;j<=2*i-1;j++)
System.out.print("*");
System.out.println();
}
for(int i=3;i>=1;i--)
{
for(int j=1;j<=2*i-1;j++)
System.out.print("*");
System.out.println();
}
}
}
跟上次差不多 2个内嵌循环
作者:
范天成
时间:
2013-1-29 20:38
class Demo1
{
public static void main(String[] args)
{
int i=1,k=7;//调整k的值可以改变打印的行数。
int j=0;
for( i=1;i<=k/2+1;i++)
{
for(j=0;j<2*i-1;j++)
System.out.print("*"+" ");
System.out.println();
}
for( i=k/2;i>=1;i--)
{
for(j=2*i-1;j>=1;j--)
System.out.print("*"+" ");
System.out.println();
}
}
}
作者:
vmvm555
时间:
2013-1-29 21:01
是这段代码吧
public class TestPrint {
public static void main(String[] args) {
for(int i = 1; i < 8; i++) {
for(int j = 1; j < 8; j++) {
if(j <= i && i % 2 == 1) {
System.out.print("* ");
}
}
System.out.println();
}
for(int i = 6; i > 0; i--) {
for(int j = 6; j > 0; j--) {
if(i >= j && i % 2 == 1) {
System.out.print("* ");
}
}
System.out.println();
}
}
}
复制代码
作者:
胥文
时间:
2013-1-30 00:09
学习了
public class PrintChar {
public static void main(String[] args) {
for(int x=0;x<4;x++)
{ for(int y=0;y<2*x+1;y++)
System.out.print("*"+" ");
System.out.println();
}
for(int x=2;x>=0;x--)
{ for(int y=2*x+1;y>0;y--)
System.out.print("*"+" ");
System.out.println();
}
}
作者:
鲁柯
时间:
2013-1-31 11:25
分成上下两部分打印
package net.test;
public class Test {
/**
* @param args
* *
* ***
* *****
* *******
* *****
* ***
* *
*/
public static void main(String[] args) {
//上边4行
for (int i=1; i<=4; i++)
{
for (int j=i; j<=2*i-1; j++)//每行内容
{
//先输出星号,注意不要换行
System.out.print("*");
}
//一行结束,换下行
System.out.println();
}
//下边3行
for (int i=3; i>0; i--)
{
//每一行的内容
for (int j=i; j<=2*i-1; j++)
{
System.out.print("*");
}
System.out.println();
}
}
}
复制代码
欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/)
黑马程序员IT技术论坛 X3.2