异常 三角形
来源:互联网 发布:淘宝店过户费用 编辑:程序博客网 时间:2024/05/22 03:51
package exception.com;
import java.util.*;
public class MyTriangle {
public static void main(String args[]){
try{
int[] s=new int[3];
int i;
System.out.println("请输入三边");
for(i=0;i<3;i++){
Scanner input=new Scanner(System.in);
s[i]= input.nextInt();
}
Arrays.sort(s); //默认从小到大
Triangle t=new Triangle();
t.triangle(s[0],s[1],s[2]);
}catch (IllegalArgumentException e){
System.out.println("不能构成三角形");
e.printStackTrace();
}
}
import java.util.*;
public class MyTriangle {
public static void main(String args[]){
try{
int[] s=new int[3];
int i;
System.out.println("请输入三边");
for(i=0;i<3;i++){
Scanner input=new Scanner(System.in);
s[i]= input.nextInt();
}
Arrays.sort(s); //默认从小到大
Triangle t=new Triangle();
t.triangle(s[0],s[1],s[2]);
}catch (IllegalArgumentException e){
System.out.println("不能构成三角形");
e.printStackTrace();
}
}
}
package exception.com;
public class Triangle {
void triangle(int a,int b,int c)throws IllegalArgumentException
// 声明异常 :throws+异常类型,用在方法头,告诉要捕获它
{
if(a+b>c&&c-a<a){
System.out.printf("三角形的三边是%d,%d,%d\n",a,b,c);
}
else{
throw new IllegalArgumentException("数据异常");
// 抛出异常:手动抛出异常 THROW+异常的对象
}
}
}
阅读全文
0 0
- 异常 三角形
- java 三角形 异常处理
- 异常处理--三角形
- 异常处理-三角形
- 异常处理-三角形
- 异常处理——三角形
- 异常处理 判断三角形三条边是否构成三角形
- 标准程序库异常处理----计算三角形面积
- Java作业-三角形判断(异常处理)
- 判断能否构成三角形(异常处理)
- 第十周——三角形三边(异常处理)
- 三角形
- 三角形
- 三角形
- 三角形
- 三角形
- 三角形
- 三角形
- windows下python环境搭建
- 基于spark实现kmeans的更新聚类中心的关键代码
- 三目运算符的理解
- leetcode 189. Rotate Array
- 前(中后)序表达式讲解
- 异常 三角形
- POJ
- LeetCode 349: Intersection of Two Arrays
- $.ajax请求中的async:false/true的作用
- 成绩转换
- Map和multimap容器
- 例题摘要
- JAVA套接字编程---UDP
- 异常 数组打印