编写字符界面的Application程序,接收依次输入的10个整型数据,每个数据一行,将这些数据按升序排序后从系统的标准输出设备输出。
【Java代码】
import java.iO.*;
import java.util.* ;
public class compositor
{
public static void main ( String args[] )
{
final int NUMBER=10;
Vector dataVector=new Vector ();
try
{
BufferedReader br=new BufferedReader (
(1) InputStreamReader ( System.in ));
System.out.println ("请输入"+NUMBER+"个整数");
for (int i=0; i<NUMBER; i++ )
{
int temp=Integer.parselnt ( br.(2));
int low=0, high=i-1, mid=0;
while ((3))
{
System.out.println ( low+","+mid+","+high );
(4);
if ((( Integer ) dataVectOr.get( mid )) .intValue () ==temp )
{
data Vector.insertElementAt ( new Integer ( temp ), mid );
break;
}
else if ((( Integer ) dataVector.get ( mid )) .intValue ( ) >temp )
{
high=mid-1;
}
else
{
(5);
}
}
if ( low>high )
{
dataVector, insertElementAt ( new Integer ( temp ), iow );
}
}
//输出
System.out.println ( "\n升序的排序结果为; ");
for (int i=0; i<NUMBER; i++ )
{
System.out.print ( dataVector.get( i ) .toString () +"\t" );
}
}
catch ( NumberFormatException nfe)
{
System.out.println ( nfe.toString ());
System.out.println ( "整数格式输入错误。");
}
catch ( IOException ioe )
{
System.out.println ( ioe.toString ());
}
}
}