Topic: SOS!(输出菱形)

  Print this page

1.SOS!(输出菱形) Copy to clipboard
Posted by: top88222
Posted on: 2006-08-16 18:06

题目:
试编写一程序输出下面图形

(这里的图可能没有整好,但是图形的轮廓是菱形)
thanks for your help

2.Re:SOS!! [Re: top88222] Copy to clipboard
Posted by: nothing
Posted on: 2006-08-16 18:53

晕。。。

3.Re:SOS!(输出菱形) [Re: top88222] Copy to clipboard
Posted by: why
Posted on: 2006-08-16 19:36

请尽量用准确的文字描述作为标题

基本上用for就行了
試用本論壇的 http://www.cjsdn.net/post/search 搜索"菱形"吧("三角形"也可)

唉--這樣的問題也不肯自己下點工夫,學甚麼Java Dead
(閣下沒寫出自己嘗試了甚麼,敝人就這麼假設;如果閣下以後還是只丟下習題,敝人也不用再看閣下的帖子了。)

4.Re:SOS!(输出菱形) [Re: top88222] Copy to clipboard
Posted by: cainiao025
Posted on: 2006-08-16 20:57

帮你一把,以后自己还是先想想自己具体哪个地方不能实现,再来问,效果会比较好,这是在下的一点忠告。运行时,在命令行输入一个整数如5或者其它。
public class Rhombus
{
public static void main(String args[])
{
int i,n;
n=Integer.parseInt(args[0]);
for(i=1;i<=n;i++)
{
for(int j=1;j<=2*n-1;j++)
{
if(j-n>-i && j-n<i)
System.out.print("*");
else
System.out.print(" ");
}
System.out.println();
}
i--;
do
{
i--;
for(int j=1;j<=2*n-1;j++)
{
if(j-n>-i && j-n<i)
System.out.print("*");
else
System.out.print(" ");

}
System.out.println();

}while(i>0);
}
}

5.Re:SOS!(输出菱形) [Re: top88222] Copy to clipboard
Posted by: top88222
Posted on: 2006-08-16 23:19

public class work10{
public static void main(String [] args){
for(int a1=5;a1<=9;a1++){
for(int a2=4;a2<a1;a2--)
System.out.print(" ");
int a3=a1-a2;
while(a3>0){
System.out.print("a");
a3--;}
if(a3==0){
System.out.println();
}
}
}
}
这是我最新写的。,但是无法编译,显示出a2的变量有问题,但是自己也没弄明白错在哪。还请大家帮帮忙。楼上的邻居,我明天会仔细的看看你的,谢谢。

6.Re:SOS!(输出菱形) [Re: top88222] Copy to clipboard
Posted by: why
Posted on: 2006-08-17 01:49

top88222 wrote:
public class work10{
public static void main(String [] args){
for(int a1=5;a1<=9;a1++){
for(int a2=4;a2<a1;a2--)
System.out.print(" ");
int a3=a1-a2;
while(a3>0){
System.out.print("a");
a3--;}
if(a3==0){
System.out.println();
}
}
}
}
这是我最新写的。,但是无法编译,显示出a2的变量有问题,但是自己也没弄明白错在哪。还请大家帮帮忙。楼上的邻居,我明天会仔细的看看你的,谢谢。

Why don't you show us the error message as well?
Most likely it is "cannot find symbol" at
int a3=a1-a2;
since a2 is undefined out of this block
for(int a2=4;a2<a1;a2--)
You need to use the curly brackets, { and }, for your for statement...

7.Re:SOS!(输出菱形) [Re: top88222] Copy to clipboard
Posted by: top88222
Posted on: 2006-08-17 09:40

since i had writtrn that where the error is ,please look at your moniter more carefully next time.

i can't understand why a2 is not undefined for "int a2=4"was written.
could you give me the explanation in detail? meanwhile i will try the measure you
told me.

8.Re:SOS!(输出菱形) [Re: top88222] Copy to clipboard
Posted by: why
Posted on: 2006-08-17 10:28

显示出a2的变量有问题 == cannot find symbol 嗎?

>could you give me the explanation in detail?
please look at your monitor more carefully next time
"since a2 is undefined out of this block"

罷了,敝人懶得再回應閣下

9.Re:SOS!(输出菱形) [Re: why] Copy to clipboard
Posted by: nothing
Posted on: 2006-08-17 10:50

楼主外语比java水平强.

10.Re:SOS!(输出菱形) [Re: nothing] Copy to clipboard
Posted by: zcjl
Posted on: 2006-08-17 11:05

nothing wrote:
楼主外语比java水平强.

赞同,可惜楼主对语言(both自然语言和Java语言)的理解能力弱于表达能力
而且,表达时也完全了忽略了一种叫做“礼貌”的素质

why wrote:
Why don't you show us the error message as well?
Most likely it is "cannot find symbol" at
int a3=a1-a2;
since a2 is undefined out of this block
for(int a2=4;a2<a1;a2--)
You need to use the curly brackets, { and }, for your for statement...


why已经在前面的帖子中给他指出了“for(int a2=4;a2<a1;a2--)”这个循环语句的作用域不包含下面的“int a3=a1-a2;”,需要正确使用{}符号,可惜他自己不会“look at your moniter more carefully”

11.Re:SOS!(输出菱形) [Re: top88222] Copy to clipboard
Posted by: top88222
Posted on: 2006-08-17 15:01

楼上的批评我对,以后会多加注意的。
但是我那“look at your .......“是想说,我已经指出自己的错误的地方。


   Powered by Jute Powerful Forum® Version Jute 1.5.6 Ent
Copyright © 2002-2021 Cjsdn Team. All Righits Reserved. 闽ICP备05005120号-1
客服电话 18559299278    客服信箱 714923@qq.com    客服QQ 714923