用java编写题目:从键盘输入5个数,排序好后输出


public class Test {

private static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

public static int getInt(){

return Integer.parseInt(getString());

}

public static String getString(){

try {

return br.readLine();

} catch (IOException e) {

return "";

}

}



public static void main(String[] args) throws IOException {

int[] s = new int[5];

for(int i=0; i<s.length; i++){

System.out.print("请输入第 "举悔 + (i+1) + " 个数: "闭郑);

s[i] = getInt();

}

System.out.println("正态正排序前: " + Arrays.toString(s));

Arrays.sort(s);

System.out.println("排序后: " + Arrays.toString(s));

}


}


StringBuffer sb=new StringBuffer()
int i=0;
while(true)
{
try{

String s= System.in.read();

sb.append(s);

i++;

}catch(Exception e){

System.out.println("输备颂激入有误请重樱灶新输仿袜入:");}
if(i==5)

break;
}:

sb.reverse()
for(int j;j<sb.size();j++)
System.out.println(sb.get(j));
import java.util.Scanner;
public class sort {

public static void main(String args[]){

int []num = new int[5];
int temp;

for(int i=0;i<5;i++)
{
num[i] = new Scanner(System.in).nextInt();
}

for(int i=0;i<5;i++)
for(int j=0;j<4;j++)
if(num[j]>num[j+1])
{
temp = num[j+1];

num[j+1] = num[j];
num[j] = temp;

}
for(int i=0;i<5;i++)
System.out.println(num[i]);
}

}