第五次实训

1.

package aaa;
import java.util.*;
public class exceptiontest {
	
	
		public static int chu(int a,int b){
			return	a/b;
			}
	    
		public static void main(String[] args){
	    Scanner cn=new Scanner(System.in);
	    int a=cn.nextInt();
	   cn.nextLine();
	    int b=cn.nextInt();
	    	try{
	    		chu(a,b);
	    	   }catch(Exception e1){
	    		  System.out.println("程序异常:"+e1); 
	    	   }finally{
	    		   System.out.println("运行结束");
	    	   }
	    }
	}

 2.

package aaa;
import java.util.*;
public class yuan {
	public static double yuanban(double r){
		return r*r*3.14;
	}
  public static void main(String[]args){
	  Scanner ex=new Scanner(System.in);
	  double r=ex.nextInt();
	  try{
		  yuanban(r);
		  System.out.println("其面积为:"+yuanban(r));
	  }catch(Exception e1){
		  System.out.println("异常为"+e1);
	  }finally{
		  System.out.println("结果错误");
	  }
  }
}

 3.

package disici;
import java.util.*;
public class id {
private String id;
public void setId(String id){
if (id.length() == 18) {
this.id = id;
} else {
throw new IllegalArgumentException("长度应为18!");
}
}
public int[] Scan(String a) {
int c[] = null;
for (int i=0;i<18;i++)
{
Scanner ex=new Scanner (System.in);
int b =ex.nextInt();
c[i]=b;
}
return c;
}

public static void main(String[] args) {
id te = new id();
String b = null;
try {
te.Scan(b);
} catch (IllegalArgumentException ie) { 
System.out.println(ie.getMessage());
}finally{
System.out.println("结束");
}
}
}

原文地址:https://www.cnblogs.com/123456Crazy111/p/10832528.html