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);
}
}
}
}
}
}
|
|