Document

今天写代码来了一个异常

/**
 * 需求分析:根据输入的天数是否是周六或是周日,
 * 并且天气的温度大于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输入的为整数,就没有异常,一旦输入了小数就会出现异常

 解决方法:

原文地址:https://www.cnblogs.com/chenyanlong/p/7667438.html