请教各位大虾多多指教,为什么下面这段程序运行后,五个数字全都显示数组中a[0]里的数字呢?小妹万分感激
import java.io.*;
public class maopao1 {
public static void main (String[] args) {
int a[]=new int[5];
    int i,j,x;
try

System.out.println("请输入5个整数:");
for(int s=0;s<5;s++)
a[s]=Integer.parseInt(new BufferedReader(new InputStreamReader(System.in)).readLine());
}catch (IOException e) { }
for(i=1;i<5;i++)
for(j=1;j<5-i;j++)
{
if(a[j]>a[j+1])
{
x=a[j];
a[j]=a[j+1];
a[j+1]=x;
}
}
System.out.println("排序结果是:");
for(int s=0;s<5;s++)
System.out.print(" "+a[s]);
}    
}

解决方案 »

  1.   

    for(i=1;i<5;i++)
    for(j=1;j<5-i;j++)
    怎么是以1开始的呢?
      

  2.   

    我练习的时候写的接收字符串然后排序输出的
    仅供参考~import java.util.Arrays;
    import java.util.Scanner;public class MaxMin2 {
    public static void main(String[] args) {
    int[] a = new int[10];
    for (int i = 0; i < 10; i++ ){
    String k;
    switch(i+1) {
    case 1:   k = i + 1 + "st";  break;  
    case 2:   k = i + 1 + "nd";  break;
    case 3:   k = i + 1 + "rd";  break;
    case 10:  k ="last";         break;
    default:  k = i + 1 + "th"; 
    }
    System.out.println("Please input the " + k +" digit:");
    Scanner in = new Scanner(System.in);
    a[i] = in.nextInt();
    }

    Arrays.sort(a);
    for (int i = 0; i < 10 ; i++) {
    System.out.print(a[i] + "\t");
    }
    System.out.println();
    System.out.println("You've input the largest is " + a[9]);
    System.out.println("You've input the smallest is "  + a[0]);
    }}
      

  3.   

    import java.io.*;
    public class maopao1 {
    public static void main (String[] args) {
    int a[]=new int[5];
        int i,j,x;
    try

    System.out.println("请输入5个整数:");
    for(int s=0;s<5;s++)
    a[s]=Integer.parseInt(new BufferedReader(new InputStreamReader(System.in)).readLine());
    }catch (IOException e) { }
    for(i=1;i<5;i++)
    for(j=0;j<5-i;j++)
    {
    if(a[j]>a[j+1])
    {
    x=a[j];
    a[j]=a[j+1];
    a[j+1]=x;
    }
    }
    System.out.println("排序结果是:");
    for(int s=0;s<5;s++)
    System.out.print(" "+a[s]);
    }    
    }
    给分啊!!
      

  4.   

    import java.io.*;
    public class Maopao {
    public static void main (String[] args) {
    int a[]=new int[5];
    try {
    System.out.println("Please input five digits:");
    for(int s=0;s<5;s++)
    a[s]=Integer.parseInt(new BufferedReader(new InputStreamReader(System.in)).readLine());
    }catch (IOException e) { }
    for(int i=1;i<5;i++)
    for(int j=0;j<5-i;j++) {
    if(a[j]>a[j+1]) {
    int x=a[j];
    a[j]=a[j+1];
    a[j+1]=x;
    }
    }
    System.out.println("The result is ");
    for(int s=0;s<5;s++)
    System.out.print(" "+a[s]);
    }
    }这是你的程序
    改了一点点,就是那两个for循环那里,
    外面一个for循环是执行比较的轮数
    里面一个for循环是执行两两相邻间的比较
    注意初始值的问题就好了。。
    另外提醒一下,类的第一个字母要大写
    写大括号的习惯是左大括号写在句末
      

  5.   

    import java.io.*;
    public class maopao1
    {
    public static void main(String args[])throws Exception
    {
    int array[] = new int[5];
    String str;
    System.out.println("请输入5个整数:");
    BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
    for(int i=0;i<array.length;i++)
    {
    str = in.readLine();
    array[i] = Integer.parseInt(str);
    }
    for(int i=0;i<array.length-1;i++)
    {
    for(int j=i+1;j<array.length;j++)
    {
    int a;
    if(array[i]>array[j])
    {
    a = array[i];
    array[i] = array[j];
    array[j] = a;
    }
    }
    }

    for(int i=0;i<array.length;i++)
    {
    System.out.println("array["+i+"]="+array[i]);
    }
    }
    }