| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 512 人关注过本帖
标题:帮我看下这程序哪里错了?
只看楼主 加入收藏
wsckt
Rank: 2
来 自:java风暴
等 级:论坛游民
帖 子:44
专家分:75
注 册:2009-10-20
结帖率:80%
收藏
已结贴  问题点数:20 回复次数:1 
帮我看下这程序哪里错了?
//file name:PAIXU_.java
import   *;
public class PAIXU_
{   
    public static void main(String[] args)    {
        
        int[] array = new int[10];
        System.out.println("输入一组数:");
          for(int i=0;i< array.length;i++)  {   
              BufferedReader stdin=new BufferedReader(new InputStreamReader(System.in));   
               array[i] = Integer.parseInt(stdin.readLine());
          }

        System.out.printf("原始数据为:\t");
        Display(array);
        System.out.printf("\n");

        Shengxu(array);
        System.out.printf("升序后数据为:\t");
        Display(array);
        System.out.printf("\n");
        
        Jiangxu(array);
        System.out.printf("降序后数据为:\t");
        Display(array);
        System.out.printf("\n");
    }
   
    public static void Shengxu(int[] array)    {
        for(int i=0;i<array.length;i++)    {
            for(int j=array.length-1;j>i;j--)    {
                if(array[j]>array[j-1])    {
                    int temp = array[j];
                    array[j] = array[j-1];
                    array[j-1] = temp;

                }
            }
        }
    }

    public static void Jiangxu(int[] array)    {
        for(int i=0;i<array.length;i++)    {
            for(int j=array.length-1;j>i;j--)    {
                if(array[j]<array[j-1])    {
                    int temp = array[j];
                    array[j] = array[j-1];
                    array[j-1] = temp;

                }
            }
        }
    }

    public static void Display(int[] array)        {
            for(int element:array)    {
                System.out.printf("%2d",element);
            
            }
    }
}
搜索更多相关主题的帖子: void public file 
2009-10-23 20:34
流星雨
Rank: 16Rank: 16Rank: 16Rank: 16
来 自:JAVA风暴
等 级:版主
威 望:43
帖 子:1854
专家分:1868
注 册:2004-5-30
收藏
得分:20 
package text;
 
import
import
import
 
public class PAIXU_ {
     public static void main(String[] args)    {
            
            int[] array = new int[10];
            array[0] =1;array[1] =3;
           
              for(int i=0;i< array.length;i++)  {   
                  System.out.println("输入一组数:"); //你将这里的输出写到这里就明显了.
                  BufferedReader stdin=new BufferedReader(new InputStreamReader(System.in));   
                  
                   try {
                    array[i] = Integer.parseInt(stdin.readLine());  //输入的时候每次回车只能读取一个字符.
                     
                } catch (NumberFormatException e) { //这里要抛出一个NumberFormatException
                    // TODO 自动生成 catch 块
                    e.printStackTrace();
                } catch (IOException e) {
                    // TODO 自动生成 catch 块
                    e.printStackTrace();
                }  
              }
 
            System.out.printf("原始数据为:\t");
            Display(array);
            System.out.printf("\n");
 
            Shengxu(array);
            System.out.printf("升序后数据为:\t");
            Display(array);
            System.out.printf("\n");
            
            Jiangxu(array);
            System.out.printf("降序后数据为:\t");
            Display(array);
            System.out.printf("\n");
        }
         
        public static void Shengxu(int[] array)    {
            for(int i=0;i<array.length;i++)    {
                for(int j=array.length-1;j>i;j--)    {
                    if(array[j]>array[j-1])    {
                        int temp = array[j];
                        array[j] = array[j-1];
                        array[j-1] = temp;
 
                    }
                }
            }
        }
 
        public static void Jiangxu(int[] array)    {
            for(int i=0;i<array.length;i++)    {
                for(int j=array.length-1;j>i;j--)    {
                    if(array[j]<array[j-1])    {
                        int temp = array[j];
                        array[j] = array[j-1];
                        array[j-1] = temp;
 
                    }
                }
            }
        }
 
        public static void Display(int[] array)        {
                for(int element:array)    {
                    System.out.printf("%2d",element);
                 
                }
        }
 
}



输入一组数:
1
输入一组数:
2
输入一组数:
3
输入一组数:
4
输入一组数:
5
输入一组数:
6
输入一组数:
6
输入一组数:
7
输入一组数:
7
输入一组数:
7
原始数据为:     1 2 3 4 5 6 6 7 7 7
升序后数据为:     7 7 7 6 6 5 4 3 2 1
降序后数据为:     1 2 3 4 5 6 6 7 7 7
//你的代码并没有什么错误,只是array[i] = Integer.parseInt(stdin.readLine());  输入的时候每次回车只能读取一个字符.其实你稍微用点心把代码运行一下就知道了.

感谢你们带我找到星空下美丽神话,无论经历多少苦痛也不放弃的梦;插上希望翅膀乘风我和你们飞翔,飞过海天尽头携手把梦想实现.....
2009-10-24 00:57
快速回复:帮我看下这程序哪里错了?
数据加载中...
 
   



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

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