Exception in thread "main" java.util.InputMismatchException


今天写代码来了一个异常

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

 解决方法:

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM