今天寫代碼來了一個異常
/**
* 需求分析:根據輸入的天數是否是周六或是周日,
* 並且天氣的溫度大於28攝氏度,則外出游泳,否則釣魚
* @author chenyanlong
* 日期:2017/10/14
*/
package com.hp.test03;
import java.util.Scanner;
public class HS_JudgeOutgoing {
public static void main(String[] args) {
// TODO Auto-generated method stub
int day;
double temperature;
//double temperature = 0.0;
System.out.println("請輸入今天星期幾,如果周n ,請輸入”n“,eg:7");
Scanner input=new Scanner(System.in);
day=input.nextInt();
if(day==6||day==7){
//溫度判斷
System.out.println("請輸入今天的溫度,eg:29.8");
Scanner input2=new Scanner(System.in);
temperature=input2.nextInt();
if(temperature>25){
System.out.println("今天適合——游泳");
}else{
System.out.println("今天適合——釣魚");
}
}else{
System.out.println("你還是老實寫代碼!!");
}
}
}
如果temperature輸入的為整數,就沒有異常,一旦輸入了小數就會出現異常

解決方法:

