当前位置: 代码迷 >> Java相关 >> 帮我看下这程序哪里错了?
  详细解决方案

帮我看下这程序哪里错了?

热度:126   发布时间:2009-10-23 20:34:18.0
帮我看下这程序哪里错了?
//file name:PAIXU_.java
import   java.io.*;
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  

----------------解决方案--------------------------------------------------------
package text;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

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());  输入的时候每次回车只能读取一个字符.其实你稍微用点心把代码运行一下就知道了.

----------------解决方案--------------------------------------------------------
  相关解决方案