打印出如下图案

cui4029 2008-05-20 12:31:58
【程序18】
题目:两个乒乓球队进行比赛,各出三人。甲队为a,b,c三人,乙队为x,y,z三人。已抽签决定比赛名单。有人向队员打听比赛的名单。a说他不和x比,c说他不和x,z比,请编程序找出三队赛手的名单。
1.程序分析:判断素数的方法:用一个数分别去除2到sqrt(这个数),如果能被整除, 则表明此数不是素数,反之是素数。
【程序19】
题目:打印出如下图案(菱形)
*
***
******
********
******
***
*
...全文
481 25 打赏 收藏 转发到动态 举报
写回复
用AI写文章
25 条回复
切换为时间正序
请发表友善的回复…
发表回复
skyqiang 2008-05-26
  • 打赏
  • 举报
回复
1.main()
{
char i,j,k;/*i是a的对手,j是b的对手,k是c的对手*/
for(i='x';i<='z';i++)
 for(j='x';j<='z';j++)
 {
 if(i!=j)
  for(k='x';k<='z';k++)
  { if(i!=k&&j!=k)
   { if(i!='x'&&k!='x'&&k!='z')
   printf("order is a--%c\tb--%c\tc--%c\n",i,j,k);
   }
  }
 }
}
------------------------------------------------
2.main()
{
int i,j,k;
for(i=0;i<=3;i++)
 {
 for(j=0;j<=2-i;j++)
  printf(" ");
 for(k=0;k<=2*i;k++)
  printf("*");
 printf("\n");
 }
for(i=0;i<=2;i++)
 {
 for(j=0;j<=i;j++)
  printf(" ");
 for(k=0;k<=4-2*i;k++)
  printf("*");
 printf("\n");
 }
}
cui4029 2008-05-23
  • 打赏
  • 举报
回复
夜空的大猩猩SORRY,分我给分错了, 我给你分,你来我下一个问题!
cui4029 2008-05-23
  • 打赏
  • 举报
回复
晕死,给分给错了,SORRY!
LoveJava520 2008-05-21
  • 打赏
  • 举报
回复
[Quote=引用 21 楼 huxinyu929 的回复:]
引用 6 楼 vcshcn 的回复:
println(" *");
println(" ***");
println(" ******");
println("********");
println(" ******");
println(" ***");
println(" *");


太可爱了
[/Quote]
huxinyu929 2008-05-21
  • 打赏
  • 举报
回复
[Quote=引用 6 楼 vcshcn 的回复:]
println(" *");
println(" ***");
println(" ******");
println("********");
println(" ******");
println(" ***");
println(" *");
[/Quote]

太可爱了
codeangel 2008-05-21
  • 打赏
  • 举报
回复
题目:两个乒乓球队进行比赛,各出三人。甲队为a,b,c三人,乙队为x,y,z三人。已抽签决定比赛名单。有人向队员打听比赛的名单。a说他不和x比,c说他不和x,z比,请编程序找出三队赛手的名单。
很明显
a->z
b->x
c->y
  • 打赏
  • 举报
回复
难道是按照 2 3 2 3 ... 的规律来递增的?
  • 打赏
  • 举报
回复
[Quote=引用 16 楼 da11393 的回复:]
引用 15 楼 bao110908 的回复:
Java codepublicclassTest {publicstaticvoidmain(String[] args) {intline=7;
line=line%2==0?line+1: line;for(intm=line/2, i=-m; i <=m; i++) {for(intj=-m, n=m-Math.abs(i); j <=n; j++) {
System.out.print(Math.abs(i)+Math.abs(j)>m?'':'*');
}
System.out.println();
}
}
}

Java code*************************


如果我没看错的话,原题各行*的个数要求1,3,6,8,6,3,1
你的output明显有误。
[/Quote]

我感觉原题是不是弄错啦?1 3 6 8 6 3 1 这样输入的菱形是个往左边歪的,并不是一个正菱形啊。

如果是这样的话,我的那段代码肯定是不对了。。。。
cui4029 2008-05-20
  • 打赏
  • 举报
回复
18题没有思路,请给个思路?
19题列数是 1 3 6 8 我觉得不对,有问题。找不出规律来!!!!
siyue_qi 2008-05-20
  • 打赏
  • 举报
回复
好好看看控制流,什么if,for等等,这就是考那些东西
晓筱时代 2008-05-20
  • 打赏
  • 举报
回复
课本上的练习题吧
coolhty 2008-05-20
  • 打赏
  • 举报
回复
第一道题.
package com.demo.test;

class ThreeRen{
public static void main(String[] args){
int i,j,g;
for(i='x';i<='z';i++){
for(j='x';j<='z';j++){
if(i!=j){
for(g='x';g<='z';g++){
if(i!='x' && g!='x' && g!='z'){
System.out.println ("a:"+(char)i+" b:"+(char)j+" c:"+(char)g);
}
}
}
}
}
}
}


不好意思,算法有点差..只有用笨点的方法解决..
da11393 2008-05-20
  • 打赏
  • 举报
回复
[Quote=引用 15 楼 bao110908 的回复:]
Java codepublicclassTest {publicstaticvoidmain(String[] args) {intline=7;
line=line%2==0?line+1: line;for(intm=line/2, i=-m; i<=m; i++) {for(intj=-m, n=m-Math.abs(i); j<=n; j++) {
System.out.print(Math.abs(i)+Math.abs(j)>m?'':'*');
}
System.out.println();
}
}
}

Java code*************************
[/Quote]

如果我没看错的话,原题各行*的个数要求1,3,6,8,6,3,1
你的output明显有误。
  • 打赏
  • 举报
回复
public class Test {
public static void main(String[] args) {
int line = 7;
line = line % 2 == 0 ? line + 1 : line;
for(int m = line / 2, i = -m; i <= m; i++) {
for(int j = -m, n = m - Math.abs(i); j <= n; j++) {
System.out.print(Math.abs(i) + Math.abs(j) > m ? ' ' : '*');
}
System.out.println();
}
}
}


   *
***
*****
*******
*****
***
*
da11393 2008-05-20
  • 打赏
  • 举报
回复
哈哈,我喜欢图形题,简单做了一下,希望cui4029满意

public class ToCui4029 {

/**
* By 夜空的大猩猩
*/

private int x = 8, y = 7;

public void initArray() {
for (float i = y, j = 1; i >= 1 && j <= y; i--, j++) {
int temp = Math.round(x * (y - Math.abs(i - j)) / y);
for (int k = 1; k <= (x - temp) / 2; k++) {
System.out.print(" ");
}
for (int k = 1; k <= temp; k++) {
System.out.print("*");
}
System.out.println();
}
}

public static void main(String[] args) {
ToCui4029 t = new ToCui4029();
t.initArray();
}
}

输出:
*
***
******
********
******
***
*
liujiajun8888 2008-05-20
  • 打赏
  • 举报
回复
18题最简答的就是你把所有可能的组合列举出来,然后根据条件筛选就可以了。我感觉这题原意就是考你if的
mike123hl 2008-05-20
  • 打赏
  • 举报
回复
7个System.out.println();搞定
幽谷无魂 2008-05-20
  • 打赏
  • 举报
回复
这是学C的时候做了的
考的是逻辑循环问题
自己思考吧,这样对你有好处的,这我深有体会
apples_009 2008-05-20
  • 打赏
  • 举报
回复
[Quote=引用 6 楼 vcshcn 的回复:]
println(" *");
println(" ***");
println(" ******");
println("********");
println(" ******");
println(" ***");
println(" *");
[/Quote]
高呀...
psyl 2008-05-20
  • 打赏
  • 举报
回复
[Quote=引用 6 楼 vcshcn 的回复:]
println("   *");
println("  ***");
println(" ******");
println("********");
println(" ******");
println("  ***");
println("   *");
[/Quote]
加载更多回复(5)

62,615

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧