| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 862 人关注过本帖
标题:java 结果是乱码 帮我看看哪里错了,谢谢啦
只看楼主 加入收藏
老男孩123
Rank: 1
等 级:新手上路
帖 子:43
专家分:0
注 册:2013-9-6
收藏
得分:0 
package ss;

public class a15 {
    public static boolean isSorted(int table[])
    {
        int i;
        
        
        for(i=0;i<table.length-1;i++)
        {
            if(table[i]>table[i+1])
               
            
                return false;
            break;
                 
            
               
        }
        
        return  true;
   
    }
   
public static void main(String[] args)
{
    int table[]={1,2,5,4,5};
   
    System.out.println(isSorted(table));
}
}
2014-03-11 22:31
老男孩123
Rank: 1
等 级:新手上路
帖 子:43
专家分:0
注 册:2013-9-6
收藏
得分:0 
这个结果居然是对的
2014-03-11 22:32
wenjinruo
Rank: 1
来 自:湖北
等 级:新手上路
帖 子:1
专家分:1
注 册:2012-9-14
收藏
得分:1 
你那个比较数组会越界吧
我贴一下我的代码
public class Test {
    public static String isSorted(int table[])
    {
        int i;
        int count1=0;
        int count2=0;
        

        for(i=0;i<table.length-1;i++)
        {
            if(table[i]>table[i+1]){
                count1++;
            }else if(table[i]<table[i+1]){
                count2++;
            }
               
        }
        if(count1==table.length-1||count2==table.length-1){
            return "The number is sorted";
        }else{
            return "The number is not sorted";
        }
        
        
        
        
    }
   
public static void main(String[] args)
{
    int table[]={1,7,4,5};
    System.out.println(isSorted(table));
    for(int j=0;j<table.length;j++){
        System.out.println(table[j]);
    }
   
}
}
2014-03-12 01:52
雪碧透心凉
Rank: 3Rank: 3
等 级:论坛游侠
威 望:2
帖 子:40
专家分:131
注 册:2014-2-26
收藏
得分:0 
回复 10楼 老男孩123
你把执行的结果贴出来

  assume nothing,do more, need less,smile often and realize how fortunate you are right now.
2014-03-12 09:24
雪碧透心凉
Rank: 3Rank: 3
等 级:论坛游侠
威 望:2
帖 子:40
专家分:131
注 册:2014-2-26
收藏
得分:0 
回复 13楼 wenjinruo
学习了

  assume nothing,do more, need less,smile often and realize how fortunate you are right now.
2014-03-12 09:28
快速回复:java 结果是乱码 帮我看看哪里错了,谢谢啦
数据加载中...
 
   



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

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