Java小實驗之資料轉換

來源:互聯網
上載者:User

標籤:es2017   []   next   mail   https   算術運算   ascii   lock   http   

看到有人問的程式,就去寫了幾行代碼,順便複習一下條件陳述式和ASCII碼

 

 1 import java.util.Scanner; 2 public class test1 { 3  4     public static void main(String[] args)  5     { 6         Scanner sc = new Scanner(System.in); 7         System.out.print("輸入一個ASCII數值:"); 8         int ascii = sc.nextInt(); 9         sc.close();10         char ch = (char)ascii;11         //在‘a’~‘z’轉成‘A’~‘Z’12         if(ch >= ‘a‘ && ch <= ‘z‘)13         {14             System.out.println((char)(ch-32));15         }16         //在‘A’~‘Z’轉成‘a’~‘z’17         else if(ch >= ‘A‘ && ch <= ‘Z‘)18         {19             System.out.println((char)(ch+32));20         }21         //在‘0’~‘9’輸出0~922         else if(ch >= ‘0‘ && ch <= ‘9‘)23         {24             System.out.println(ch);25         }26         //輸出“+ - * /”27         else if(ch == ‘+‘ || ch== ‘-‘ || ch == ‘*‘ || ch == ‘/‘)28         {29             System.out.println("屬於算術運算子");30         }31         //輸出“非法字元”32         else33         {34             System.out.println("非法字元");35         }36     }37 }

 

耑新新,發佈於  部落格園

轉載請註明出處,歡迎郵件交流:[email protected]

Java小實驗之資料轉換

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.