请完成Java程序:本题是一个冒泡排序程序的实例。冒泡排序的含义是将相邻的两个数作比较,如果是升序排列的话,如果前边的数大,则将两个数交换。从第一个数开始两两比较一次,就可以将最大的数移动到最后。注意:请勿修改main()主方法和其他已有语句内容,仅在横线处填入适当语句。import java.io.*;public class simple{public static int[]Data=new int[10];public static void main(String[] args)int i;int Index;Index=0;InputStreamReader ir;BufferedReader in;ir=new InputStreamReader(System.in);in=new BufferedReader(ir);try{do{System.out.println("Please input the number"+Index+"you want to sort(Exit for 0):");String s=in.readLine();Data[Index]=Integer.parseInt(s);Index++;}while(Data[Index-1]!=0);}catch(IOException e){System.out.println(e.getMessage());}System.out.print("Before bubble sorting:");for(i=0; i<Index-1; i++)System.out.print(" "+Data[i]+" ");System.out.println(" ");BubbleSort(Index-1);System.out.print("After Bubble Sorting:");for(i=0; i<Index-1;i++)System.out.print(" "+Data[i]+" ");System.out.println(" ");}public static void BubbleSort(int Index){int i, j, k;boolean Change;int Temp;for(j=Index; j>1;j--){Change=false;for(i=0; i<j-1;i++){if(Data[i+1]<Data[i]){Temp=Data[i+1];Data[i+1]=Data[i];______;______;}}if(Change){System.out.print("Current Sorting Result:");for(k=0; k<Index; k++)System.out.print(" "+Data[k]+" ");System.out.println(" ");}}}}
请完成Java程序:本题是一个冒泡排序程序的实例。冒泡排序的含义是将相邻的两个数作比较,如果是升序排列的话,如果前边的数大,则将两个数交换。从第一个数开始两两比较一次,就可以将最大的数移动到最后。
注意:请勿修改main()主方法和其他已有语句内容,仅在横线处填入适当语句。
import java.io.*;
public class simple
{
public static int[]Data=new int[10];
public static void main(String[] args)
int i;
int Index;
Index=0;
InputStreamReader ir;
BufferedReader in;
ir=new InputStreamReader(System.in);
in=new BufferedReader(ir);
try
{
do
{
System.out.println("Please input the number"+
Index+"you want to sort(Exit for 0):");
String s=in.readLine();
Data[Index]=Integer.parseInt(s);
Index++;
}
while(Data[Index-1]!=0);
}
catch(IOException e)
{
System.out.println(e.getMessage());
}
System.out.print("Before bubble sorting:");
for(i=0; i<Index-1; i++)
System.out.print(" "+Data[i]+" ");
System.out.println(" ");
BubbleSort(Index-1);
System.out.print("After Bubble Sorting:");
for(i=0; i<Index-1;i++)
System.out.print(" "+Data[i]+" ");
System.out.println(" ");
}
public static void BubbleSort(int Index)
{
int i, j, k;
boolean Change;
int Temp;
for(j=Index; j>1;j--)
{
Change=false;
for(i=0; i<j-1;i++)
{
if(Data[i+1]<Data[i])
{
Temp=Data[i+1];
Data[i+1]=Data[i];
______;
______;
}
}
if(Change)
{
System.out.print("Current Sorting Result:");
for(k=0; k<Index; k++)
System.out.print(" "+Data[k]+" ");
System.out.println(" ");
}
}
}
}