A股上市公司传智教育(股票代码 003032)旗下技术交流社区北京昌平校区

© changfa 中级黑马   /  2016-9-14 11:03  /  435 人查看  /  0 人回复  /   0 人收藏 转载请遵从CC协议 禁止商业使用本文

package com.heima.ch;

import java.math.BigDecimal;
import java.math.BigInteger;
import java.util.Scanner;

public class Test6 {

        /**
         * @param args
         */
        public static void main(String[] args) {
                Scanner sc = new Scanner(System.in);
                System.out.println("键盘录入一航整数:");
                while(true){
                        String line = sc.nextLine();
                        try {
                                int ni = Integer.parseInt(line);
                                System.out.println(Integer.toBinaryString(ni));
                                break;
                        } catch (Exception e) {
                                try {
                                         BigInteger s = new BigInteger(line);
                                 System.out.println("你路数的数大于int的范围:"+s);
                                } catch (Exception e2) {
                                        try {
                                                BigDecimal d = new BigDecimal(line);
                                                System.out.println("你录入是小数," + d);
                                        } catch (Exception e3) {
                                                System.out.println("你录入的是非法字符:"+line);
                                        }
                                }
                        }
                       
                }

        }

}

0 个回复

您需要登录后才可以回帖 登录 | 加入黑马