标签:ret oid class extends scanner bbb util turn color
1 package bbb; 2 3 import java.util.Scanner; 4 5 public class ccc { 6 public static void main(String [] argc){ 7 int x,y,num; 8 Scanner in = new Scanner(System.in); 9 System.out.print("请输入两个数据:"); 10 x = in.nextInt(); 11 y = in.nextInt(); 12 try{ 13 num=x/y; 14 }catch(Exception e){ 15 e.printStackTrace(); 16 System.out.println("除数不能为零"); 17 } 18 finally{ 19 System.out.println(); 20 } 21 } 22 23 }
1 package bbb; 2 3 import java.util.Scanner; 4 5 public class nida { 6 7 public static void main(String[] args) { 8 // TODO 自动生成的方法存根 9 double r,num; 10 System.out.print("请输入圆的半径:"); 11 Scanner in = new Scanner(System.in); 12 r = in.nextDouble(); 13 try{ 14 num = 3.14*r*r; 15 System.out.println(num); 16 }catch(Exception e){ 17 e.printStackTrace(); 18 } 19 } 20 21 }
1 package bbb; 2 3 import java.util.Scanner; 4 5 public class Myexcep extends Exception{ 6 public Myexcep(String ErrorMessage){ 7 super(ErrorMessage); 8 } 9 public class Tran{ 10 String avg(String s) throws Myexcep{ 11 if(s.length()!=18){ 12 throw new Myexcep("不是18个数字"); 13 } 14 return s; 15 } 16 } 17 public static void main(String[] args) { 18 // TODO 自动生成的方法存根 19 String id; 20 System.out.print("请输入身份证号码:"); 21 Scanner in = new Scanner(System.in); 22 id =in.nextLine(); 23 try{ 24 //System.out.print("身份证号码为:"); 25 System.out.print(avg(id)); 26 }catch(Exception e){ 27 //e.printStackTrace(); 28 System.out.println(e); 29 } 30 } 31 private static String avg(String id) throws Myexcep { 32 String s = id; 33 // TODO 自动生成的方法存根 34 if(s.length()!=18){ 35 throw new Myexcep("不是18个数字"); 36 } 37 System.out.print("身份证号码为:"); 38 return s; 39 } 40 41 }
标签:ret oid class extends scanner bbb util turn color
原文地址:https://www.cnblogs.com/zhangkaiz/p/10843601.html