日期:2014-05-20 浏览次数:20816 次
public static void main(String[] args) { Scanner input = new Scanner(System.in); System.out.print("请输入任意一个整数:"); int num = input.nextInt(); if (num <= 100000 && num > 0) { int count = 0; do { num = num / 10; // 提取位数 count++; } while (num > 0); System.out.println(count + "位"); } else { System.out.println("请输入10W以内数字。"); } }
------解决方案--------------------
public static void main(String args[]) { Scanner input = new Scanner(System.in); boolean b = true; while(b){ System.out.print("请输入任意一个整数:"); int num = input.nextInt(); int count = 0; do { num = num / 10; // 提取位数 count++; } while (num > 0); System.out.println(count + "位"); if(count<=5){ b = false; } } }
------解决方案--------------------
System.out.println(Integer.MAX_VALUE);
------解决方案--------------------
int 整数型范围限制
------解决方案--------------------