java編程基礎篇---------> 編寫一個程序,從鍵盤輸入三個整數,求三個整數中的最小值。


編寫一個程序,從鍵盤輸入三個整數,求三個整數中的最小值。

關鍵:聲明變量temp   與各數值比較。

 1 package Exam01;
 2 import java.util.Scanner;
 3 
 4     public class Topic03 {
 5     public static void main(String[] args) {
 6     // TODO Auto-generated method stubint a,b,c;
 7     //輸入
 8     Scanner input = new Scanner(System.in);
 9     System.out.println("請輸入一個整數:");
10     a = input.nextInt();
11     System.out.println("請輸入二個整數:");
12     b = input.nextInt();
13     System.out.println("請輸入三個整數:");
14     c = input.nextInt();
15     System.out.println(a+","+b+","+c);
16     int temp;int min;
17     if(a>b){
18         temp = a;
19         a = b;
20         b = temp;
21     }
22     if(a>c){
23         min = b;
24     }else{
25         min = a;
26     }if(min>c){
27         min = c;
28     }
29         System.out.println("最小值:" + min);
30     }
31 }                

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM