随笔分类 - 大二上ppt作业
摘要:1 . System.out.println("请输入文件夹的地址: "); String address; Scanner sc=new Scanner(System.in); address=sc.nextLine(); File folder=new File(address); int su
阅读全文
摘要:在c++中我们的异常处理一般是返回一个数值,通过判断数值来决定执行那一步,但在java中引入了异常类 可以供我们方便的处理异常下面介绍一些java异常类的基本结构: Throwable是所有异常类的基类,它之下分为:Error与Exception. 其中Error是严重错误,一般为硬件错误,我们一般
阅读全文
摘要:1. public static void main(String[] a) { int i=1, j=0, k; k=i/j; try { k = i/j; // Causes division-by-zero exception //throw new Exception("Hello.Exce
阅读全文
摘要:以下是运行结果: 我们来分析一下为何会有如下结果: 首先 Parent parent=new Parent(); parent.printValue(); Child child=new Child(); child.printValue(); 分别输出父类和子类各自的myValue,100和200
阅读全文
摘要:1. 父类: public class Father { public void showOut() { System.out.println("这是父类方法!"); } } 子类: public class Son extends Father{ public void showOut() { s
阅读全文
摘要:1. public class test5 { public static void main(String[] args) { Foo obj1=new Foo(); Foo obj2=new Foo(); Foo obj3=obj1; System.out.println(obj1==obj2)
阅读全文
摘要:1.纯随机数发生器 利用随机数发生器公式 X(n+1)=(aX(n)+c)mod m; 其中设定m=int.MaxValue=2^31-1,a=7^5=16807,c=0; 可以利用递推,利用System.currentTimeMillis()返回时间在除以10000,当做第一个数。 public
阅读全文
摘要:1.枚举类 public class EnumTest { public static void main(String[] args) { Size s=Size.SMALL; Size t=Size.LARGE; //s和t引用同一个对象? System.out.println(s==t); /
阅读全文