題目可輸入四個人名與分數並依序排序輸出由小至大的人名與分數
package ch5;
import java.io.*;
public class ch5_12_3
{
public static void main(String args[])throws IOException
{
InputStreamReader in=new InputStreamReader(System.in);
BufferedReader buf=new BufferedReader(in);
int a=45,b=34,c=23,d=55,t;
String sa,sna="A",sb,snb="B",sc,snc="C",sd,snd="D",snt;
/*先跳過輸入環節來省時間
sna=buf.readLine();
sa=buf.readLine();
a=Integer.parseInt(sa);
snb=buf.readLine();
sb=buf.readLine();
b=Integer.parseInt(sb);
snc=buf.readLine();
sc=buf.readLine();
c=Integer.parseInt(sc);
snb=buf.readLine();
sd=buf.readLine();
d=Integer.parseInt(sd);
*/
if(a>b)
{t=a;a=b;b=t;snt=sna;sna=snb;snb=snt;}
if(b>c)
{t=b;b=c;c=t;snt=snb;snb=snc;snc=snt;}
if(c>d)
{t=c;c=d;d=t;snt=snc;snc=snd;snd=snt;}
if(a>b)
{t=a;a=b;b=t;snt=sna;sna=snb;snb=snt;}
if(b>c)
{t=b;b=c;c=t;snt=snb;snb=snc;snc=snt;}
if(a>b)
{t=a;a=b;b=t;snt=sna;sna=snb;snb=snt;}
System.out.println("分數排序由小至大"+sna+"分數"+a+","+snb+"分數"+b+","+snc+"分數"+c+","+snd+"分數"+d);
}
}
=====================
分數排序由小至大C分數23,B分數34,A分數45,D分數55
請先 登入 以發表留言。