zoukankan      html  css  js  c++  java
  • java第5次作业

    import java.util.;
    public class FIVE {
    public static void main(String args[]){
    int i,j,s = 0;
    Scanner sc = new Scanner(System.in);
    i = sc.nextInt();
    j = sc.nextInt();
    try{
    s = i/j;
    }
    catch(ArithmeticException e)
    {
    e.printStackTrace();
    }
    {
    System.out.println(s);
    }
    }
    }
    2
    import java.util.Scanner;
    public class shiyan1 {
    @SuppressWarnings("resource")
    public static void main(String[] args) {
    // TODO Auto-generated method stub
    double r;
    Scanner s = new Scanner(System.in);
    while(true){
    try{
    r = Double.parseDouble(s.next());
    if(r<0)
    throw new NegativeException();
    else if(r<1.0||r>100.0)
    throw new NumberRangeException();
    else{
    System.out.println("面积是"+3.14r*r);
    break;
    }
    }catch(NumberFormatException e){
    System.out.println("非数值异常");
    }catch(NegativeException e){
    System.out.println("负数异常");
    }catch(NumberRangeException e){
    System.out.println("越界异常");
    }
    }
    }
    }
    class NegativeException extends Exception{
    private static final long serialVersionUID = 1L;
    public NegativeException(){
    super();
    }
    public NegativeException(String msg){
    super(msg);
    }
    public NegativeException(String msg, Throwable cause){
    super(msg,cause);
    }
    public NegativeException(Throwable cause){
    super(cause);
    }
    }
    class NumberRangeException extends Exception{
    public NumberRangeException(){
    super();
    }
    public NumberRangeException(String msg){
    super(msg);
    }
    public NumberRangeException(String msg, Throwable cause){
    super(msg,cause);
    }
    public NumberRangeException(Throwable cause){
    super(cause);
    }
    }
    3
    public class shiyan2 {
    private String id;
    public void setid(String id) {
    if(id.length()==18)
    this.id=id;
    else
    throw new IllegalArgumentException("参数长度应为18!");
    }
    public static void main(String[] args) {
    // TODO Auto-generated method stub
    shiyan2 t =new shiyan2();
    try {
    t.setid("0123456789123456789");
    }catch(IllegalArgumentException ie) {
    System.out.println(ie.getMessage());
    }finally {
    System.out.println("结束");
    }
    }
    }

  • 相关阅读:
    (转)JAVA国际化
    (转)实现这两个接口ModelDriven<T>,Preparable有什么用?
    cordova 与 phonegap关系
    NApache+JBOSS架构方案
    (转)Java 标注(Annotation)详解
    Jboss集群(五)--F5硬件负载均衡器双击热备 + Jboss集群终极实现
    GTK+/GNOME编程(一)
    二维数组中查找指定的数
    计算字符串距离
    统计指定数字的个数,并将其按权值10的次方数相加
  • 原文地址:https://www.cnblogs.com/nicejun/p/11135011.html
Copyright © 2011-2022 走看看