作者z1235379999 (KU HAN HSIANG)
看板java
標題[J2SE] 新手查詢最大最小值
時間Mon Oct 8 20:24:50 2012
import java.io.* ;
public class z1235379999 {
public static void main(String[] args){
String a = "" ;
String b = "" ;
String c = "" ;
String d = "" ;
String e = "" ;
BufferedReader br =
new BufferedReader(new InputStreamReader(System.in)) ;
try{
System.out.println("a:");
a = br.readLine() ;
System.out.println("b:");
b = br.readLine() ;
System.out.println("c");
c = br.readLine() ;
System.out.println("d");
d = br.readLine() ;
System.out.println("f");
e = br.readLine() ;
int f = Integer.parseInt(c);
int g = Integer.parseInt(d);
int h = Integer.parseInt(e);
System.out.println("****************************\na:"+a+"\tb:"+b+"\nc:"+c+"\td:"+d+"\tf:"+e+"\n
平均:"+(f+g+h)/3+"\t加總:"+(f+g+h)+"\n****************************") ;
}catch(Exception ex){
}
}
}
上面這個程式是小弟從自學書裡面的範例來改的
小弟想問一下
最後顯示的地方如果要印出輸入的最大值跟最小值的話要怎麼打?
小弟想了很久還是想不通...
希望有大大能幫忙
感謝!
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 112.104.51.77
推 LaPass:"最大:"+Math.max(f,Math.max(g,h)) 最小...把max改成min 10/08 20:28
→ z1235379999:LaPass大大我剛剛正想寫信給你! 10/08 20:32
推 Expsun:氣泡排序? 10/08 21:59
推 pupuliao:想要自己寫排序的話,這種量 用氣泡就夠了... 10/09 03:04
→ OrzOGC:資料丟進陣列.sort.比自己寫快多了 10/09 07:52