分享到:
发表于 2009-08-16 16:07:05 楼主 | |
如何从键盘输入一个4位以上的整数并赋给一个整型变量
|
|
楼主热贴
个性签名:无
|
发表于 2009-08-31 21:21:01 1楼 | |
路过 | |
发表于 2010-10-31 18:21:27 2楼 | |
顶 | |
发表于 2011-08-30 09:53:59 3楼 | |
支持楼主!! | |
发表于 2011-09-03 18:00:46 4楼 | |
看代码吧! import java.util.Scanner; public class Example { public static void main(String[] args) { while (true) { System.out.println("type a integer at least bigger than 1000"); Scanner scanner = new Scanner(System.in); String numberStr = ""; numberStr = scanner.next(); if (numberStr.length() < 4) { System.out .println("the integer you input not bigger than 1000,please retry!"); scanner = new Scanner(System.in); continue; } int input = Integer.parseInt(numberStr); System.out.println("the integer you input is " + input); break; } } } |
|
发表于 2011-09-03 20:30:45 5楼 | |
|
|
发表于 2011-12-27 16:51:09 6楼 | |
您的内容正在火速审核中,请稍等 |
|
针对ZOL星空(中国)您有任何使用问题和建议 您可以 联系星空(中国)管理员 、 查看帮助 或 给我提意见