- 博客(13)
- 收藏
- 关注
原创 异常的小习题
public class TestException{ public static void main(String args[]) { TestData data=new TestData(0,2); try { int c=data.chu(data.a, data.b); if(c==0) throw new Exception("Exception")
2014-02-27 16:40:21 360
原创 定义自己的异常类
public class MineException extends Exception{ public static void main(String args[]) { try { throw new Mine("出现异常!"); } catch(Mine x) { System.out.println("Exception!"); } }}cl
2014-02-27 16:24:40 378
原创 在指定方法中抛出异常,在调用该方法的地方处理异常
public class MethodException{ public static void main(String args[]) { Test test=new Test(2,0); try { test.sub(test.a,test.b); } catch(Exception x) { System.out.println("出现异常!");
2014-02-27 15:50:14 2665
原创 程序中抛出异常
public class ThrowException{ public static void main(String args[]) { try { int a=6,b=0; if(b==0) throw new ArithmeticException("算术异常!"); } catch(ArithmeticException x) {
2014-02-27 15:26:24 629
原创 异常变量输出时,是输出异常类
public class ExceptionObject{ public static void main(String args[]) { try { int []a=new int[10]; a[10]=10; } catch(ArrayIndexOutOfBoundsException x) { System.out.println("数组边界溢出
2014-02-27 11:18:14 515
原创 异常处理过程
public class ExceptionTest{ static int []a=new int[5]; public static void main(String args[]) { try { for(int i=0;i<=5;i++) { a[i]=i; } } catch(ArrayIndexOutOfBoundsException
2014-02-27 10:50:14 502
原创 注意访问级别的使用,尤其是不同包的加载时如何调用
package package01;import package02.Student;public class StudentData{ public static void main(String args[]) { Student stu=new Student("Lily","two",23); System.out.println(stu); }}package
2014-02-26 16:51:56 433
原创 不同包的导入,调用
package pack1;import pack2.Test02;public class Test01{ public static void main(String args[]) { Test02 test=new Test02(23,"Rick"); System.out.println(test); }}package pack2;public clas
2014-02-26 16:00:27 415
原创 学生成绩,年龄排序实现
import java.util.*;public class ArraysTest{ public static void main(String args[]) { Student []stu=new Student[5]; stu[0]=new Student(23,91.5,"Lily"); stu[1]=new Student(22,90,"John"); stu
2014-02-26 10:29:02 631
原创 Random类产生随机数,注意是从0开始的,否则需要进行相关范围调整计算
import java.util.*;public class RandomClass{ public static void main(String args[]) { Random ran=new Random(); for(int i=0;i<5;i++) { int a=ran.nextInt(100); System.out.println(a);
2014-02-25 11:31:39 2067
原创 日期的计算
import java.util.*;public class TimeCalu{ public static void main(String args[]) { Calendar cal=Calendar.getInstance(); System.out.println("当前日期为"+cal.get(cal.YEAR)+"年,"+cal.get(cal.MONTH)+
2014-02-25 11:18:54 371
原创 打印java虚拟机的环境变量
import java.util.*;public class SystemProperties{ public static void main(String args[]) { Properties pro=System.getProperties(); Enumeration enu=pro.propertyNames(); while(enu.hasMoreElemen
2014-02-25 10:26:44 630
原创 注意JAVA中链接操作符的使用"+"
public class LinkSign{ public static void main(String args[]) { String a="A"; String b=a+"I o"+0; System.out.println(b); }}
2014-02-25 09:38:58 508
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人