java 鍵盤輸入一個字符,並且在控制台輸出


 

package it.heima;

import java.util.Scanner;//導入包 鍵盤輸入包
public class jianPanShuRu {

    public static void main (String [] args){

   //創建Scanner對象
        Scanner input = new Scanner(System.in);
        //提示
        System.out.println("請輸入一個數字");
        // 把鍵盤輸入的數值賦給 num
        int num = input.nextInt();
        //控制台輸出
        System.out.println("num="+num);
    }
}

 求三個數的中間值

 1 package it.heima;
 2 
 3 import java.util.Scanner;//導入包 鍵盤輸入包
 4 public class jianPanShuRu {
 5 
 6     public static void main(String[] args) {
 7 
 8         //創建Scanner對象
 9         Scanner input = new Scanner(System.in);
10         //提示
11         System.out.println("請輸入一個數字");
12         // 把鍵盤輸入的數值賦給
13         // num
14         int a = input.nextInt();
15         //控制台輸出
16         System.out.println("請輸入一個數字");
17         int b = input.nextInt();
18         System.out.println("請輸入一個數字");
19         int c = input.nextInt();
20         if(a>b & a>c & b<c){
21             System.out.println("輸出中間值" + b);
22         }
23         if(a>b & a<c ){
24             System.out.println("輸出中間值" + a);
25         }
26         if(a>b & a>c & c<b){
27             System.out.println("輸出中間值" + c);
28         }
29         if(a<b & a>c){
30             System.out.println("輸出中間值" + a);
31         }
32         if(a<b & a<c & b<c){
33             System.out.println("輸出中間值" + b);
34         }
35         if(a<b & a<c & b>c){
36             System.out.println("輸出中間值" + c);
37         }
38 
39 
40 //        if (a > b) {
41 //            if (a > c) {
42 //                if (b > c) {
43 //                    System.out.println("輸出中間值" + c);
44 //                } else {
45 //                    System.out.println("輸出中間值" + b);
46 //                }
47 //            } else {
48 //                System.out.println("輸出中間值" + a);
49 //            }
50 //        }else{//a<b
51 //            if(a>c){
52 //                System.out.println("輸出中間值" + a);
53 //            }else{//a<c
54 //                if(b>c){
55 //                    System.out.println("輸出中間值" + c);
56 //                }else{
57 //                    System.out.println("輸出中間值" + b);
58 //                }
59 //
60 //            }
61 //        }
62     }
63 }

 


免責聲明!

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



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