| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 523 人关注过本帖
标题:帮我看看,有错误
只看楼主 加入收藏
fenglin115
Rank: 1
等 级:新手上路
帖 子:1
专家分:0
注 册:2008-3-16
收藏
 问题点数:0 回复次数:1 
帮我看看,有错误
public class ysf {
public static void main(String argv[]){
String people[]=new String[30];
for(int i=0;i<=30;i++){
people[i]="+"; //所有人都在船上
}
int j=0; //数组下标
int count=0; //从1数到9
int water=0; //落水的人数
while(true){
if(people[j].equals("+")){ //满足条件计数1
count++;
//数到9
if(count==9){
people[j]="@"; //该人投入海中
water++; //落入水中人数+1
if(water==15)
break;
// 重新开始计数
count=0;
}
}
j++;
if(j>29) j=0;
}
System.out.println();
for(int i=0;i<30;i++){
System.out.println(people[i]);

歌德巴赫猜想
for(int i=6;i<=2000;i=i+2){
for(int x=2;x<=2000;x++){
y=i-x;
if(MathUtil.isSuShu(x)&MathUtil.isSuShu(y)){
System.out.println(x+"+"+y);
break;
}
搜索更多相关主题的帖子: public people count 
2008-03-28 21:13
两岁半
Rank: 1
等 级:新手上路
帖 子:8
专家分:0
注 册:2007-12-28
收藏
得分:0 
你的书写不太好,要有层次
package com;
public class Ysf {

    public static void main(String argv[]) {

        String people[] = new String[30];

        for (int i = 0; i < people.length; i++) {

            people[i] = "+";     // 所有人都在船上
        }

        int j = 0;                 // 数组下标
        int count = 0;             // 从1数到9
        int water = 0;             // 落水的人数

        while (true) {
            if (people[j].equals("+")) {     // 满足条件计数1

                count++;
                // 数到9
                if (count == 9) {
                    people[j] = "@";         // 该人投入海中
                    water++;                 // 落入水中人数+1
                    if (water == 15)
                        break;
                    // 重新开始计数
                    count = 0;
                }
            }

            j++;
            if (j > 29)
                j = 0;
        }

        System.out.println();
         for (int i = 0; i < 30; i++) {

            System.out.println(people[i]);

            // 歌德巴赫猜想
            for (int k = 6; k <= 2000; k += 2) {
                for (int x = 2; x <= 2000; x++) {
                    y = k - x;
                    if (MathUtil.isSuShu(x) & MathUtil.isSuShu(y)) {
                        System.out.println(x + "+" + y);
                        break;
                    }
                }
            }
        }
    }
}

还有就是"}"少的太多了,建意你在写程序时,把"{}","()"先成对打出再往里写代码,
暂时就给你指出了这些,LZ先修改一下,
我没有运行,所以也不知道结果
1.在使用数组时,数组下标是从0开始,到你定义的数组长度-1完,如
int[] array = new int [5],那么数组就是array[0],array[1]......array[4],所以你程序里for(int i=0;i<=30;i++)是错的,应该是i<30,或者是i<array.length,应该就是小于数组的长度,
2.// 歌德巴赫猜想下的Y是从哪儿来的,
3.if (MathUtil.isSuShu(x) & MathUtil.isSuShu(y)) MathUtil.isSuShu是从哪儿来的

[[it] 本帖最后由 两岁半 于 2008-3-30 11:59 编辑 [/it]]
2008-03-30 11:41
快速回复:帮我看看,有错误
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.016178 second(s), 9 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved