iT邦幫忙

2021 iThome 鐵人賽

DAY 10
0
自我挑戰組

從零開始學Java系列 第 10

Day10 Scanner(Ⅱ)

Scanner 常使用到的Methods

  1. 整數 nextInt() 2.小數 nextDouble() 3.文字 nextLine() 4.浮點數 nextFloat()
    再來一個使用Scanner的舉例!計算BMI值
    Step1:已知要設定程式給使用者輸入,所以就代表要使用Scanner
    (和上面介紹的步驟都一樣!)
    https://ithelp.ithome.com.tw/upload/images/20210922/20140457lvViNtDk0v.jpg
    Step2:要使用者輸入名字,因為名字屬於文字字串,所以要用String和nextLine
    https://ithelp.ithome.com.tw/upload/images/20210922/20140457VAUnPZj0sq.jpg
    Step3:再讓使用者輸入身高體重,這兩個會有小數,所以使用Double和nextDouble
    https://ithelp.ithome.com.tw/upload/images/20210922/20140457sLpyAmp2PX.jpg
    Step4:都設定好了之後,要告訴電腦BMI的公式,讓它計算
    https://ithelp.ithome.com.tw/upload/images/20210922/20140457J9IMQYnBRV.jpg
    Step5:最後則是輸出結果,我要名字加上BMI
    https://ithelp.ithome.com.tw/upload/images/20210922/20140457rsW5FHwrAh.jpg
    結果:https://ithelp.ithome.com.tw/upload/images/20210922/20140457hijUuSHp1u.jpg

上一篇
Day 9探討Scanner(Ⅰ)
下一篇
Day11迴圈(Ⅰ)
系列文
從零開始學Java30
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言