Introduction to Java Programming编程题12.2<InputMismatchException>
来源:互联网 发布:js中target属性 编辑:程序博客网 时间:2024/05/23 13:01
运行结果:
Enter two digital number: tr ru hdInvalid digital number.Enter two digital number: 45 qaInvalid digital number.Enter two digital number: 12 1112 + 11 = 23
InputException.java
import java.util.InputMismatchException;import java.util.Scanner;public class InputException { public static void main(String[] args) { Scanner input = new Scanner(System.in); do { System.out.print("Enter two digital number: "); try { int a = input.nextInt(); int b = input.nextInt(); int sum = a + b; System.out.println(a + " + " + b + " = " + sum); break; } catch (InputMismatchException ex) { System.out.println("Invalid digital number."); input.nextLine(); continue; } } while (true); }}
0 0
- Introduction to Java Programming编程题12.2<InputMismatchException>
- introduction to Java Programming 编程题5.3<回文整数>
- Introduction to Java Programming编程题5.6<打印数字三角形>
- Introduction to Java Programming编程题5.13<数列求和>
- Introduction to Java Programming编程题5.14<计算数列>
- Introduction to Java Programming编程题5.17<01矩阵>
- Introduction to Java Programming编程题5.26<回文素数>
- Introduction to Java Programming编程题5.27<反素数>
- Introduction to Java Programming编程题5.29<掷骰子游戏>
- Introduction to Java Programming编程题5.28<梅森素数>
- Introduction to Java Programming编程题5.30<双素数>
- Introduction to Java Programming编程题9.1<检查SSN>
- Introduction to Java Programming编程题9.2<检查子串>
- Introduction to Java Programming编程题7.6<两个矩阵相乘>
- Introduction to Java Programming编程题9.3<检验密码>
- Introduction to Java Programming编程题9.8<二进制转十进制>
- Introduction to Java Programming编程题9.9<二进制转十六进制>
- Introduction to Java Programming编程题9.10<十进制转二进制>
- jQuery源码分析之jQuery.cleanData和jQuery.removeData以及jQuery._removeData十五问
- 部署完openstack后的网络配置(一)
- apache, php, mysql 安装过程命令记录
- 了解LESS
- 开发自定义的View
- Introduction to Java Programming编程题12.2<InputMismatchException>
- MySQL数据库配置文件之my.ini小札记
- 深入解析Oracle 10g中SGA_MAX_SIZE和SGA_TARGET参数的区别和作用
- Service
- leetcode笔记:Reorder List
- 离散化 + 线段树(树状数组) + 线扫描法
- 阿里面试经历总结
- Longest Valid Parentheses
- hdu5491(2015合肥网络赛H题)