码迷,mamicode.com
首页 > 编程语言 > 详细

java -判断输入数据的类型

时间:2017-08-09 18:34:47      阅读:177      评论:0      收藏:0      [点我收藏+]

标签:oid   nbsp   void   test   一个   can   小数   int()   ext   

没什么说的,直接贴代码。

package java_test;
import java.util.Scanner;
public class test_Scanner {

    public static void main(String[] args) {
    // TODO Auto-generated method stub
        long Long;
        String string;
        double Double;
        Scanner s =new Scanner(System.in);
        System.out.println("输入一个整数\n\n");
        if(s.hasNextInt()){
    	     Long = s.nextLong();
    	     System.out.println("您输入的是一个整数:"+Long); 
        }
        else if(s.hasNextDouble()){
    	    Double =s.nextDouble();
    	    System.out.println("您输入的是一个小数:"+Double);
       }
        else if (s.hasNext()){
    	   string = s.nextLine();
    	   System.out.println("您输入的是一个字符串:"+string);
      }
     
    
   }
}

 

java -判断输入数据的类型

标签:oid   nbsp   void   test   一个   can   小数   int()   ext   

原文地址:http://www.cnblogs.com/yin-tao/p/7326945.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!