Random
import java.util.Random;
public class Main
{
public static void main(String args[])
{
Random r = new Random();
int a = r.nextInt();
int b = r.nextInt();
System.out.println(a);
System.out.println(b); //这里打印的结果每次都不一样
System.out.println(r.nextInt(100)); //0到99之间的数
//如果想表达0~100的话 就是r.nextInt(100)+1
int c = (int)(Math.random()*100+1); //这也是表示0到100 相互等价
int i = r.nextInt(); //产生一个随机种子
Random r2 = new Random(i); //通过种子来算的 如果i为常数的话 每次打印的结果就是一样的了
int a2 = r2.nextInt();
int b2 = r2.nextInt();
System.out.println(a2);
System.out.println(b2); //所以这里打印的结果每次也都不一样
}
}
System
==1.System.gc(); ==
public class Main
{
public static void main(String args[])
{
for(int i=0;i<=10;i++) {
new demo();
System.gc(); //呼叫垃圾清理
}
}
}
class demo
{
@Override
protected void finalize() throws Throwable {
super.finalize();
System.out.println("垃圾被清理了");
}
}
System.exit(0);
退出jvm虚拟机
public class Main
{
public static void main(String args[])
{
System.out.println(1212);
System.exit(0);
System.out.println(1111);
}
}
System.arraycopy(src, 0, dest, 0, src.length);
public class Main
{
public static void main(String args[])
{
int[] src = {11,22,33,44,55};
int[] dest =new int[8];
for(int i=0;i<dest.length;i++) {
System.out.println(dest[i]);
}
System.out.println("******************");
// 参数1为原数组 参数2为原数组的起始位置 参数3为目标数组 参数4为目标数组的起始位置 参数为数组长度
System.arraycopy(src, 0, dest, 0, src.length);
for(int i=0;i<dest.length;i++) {
System.out.println(dest[i]);
}
}
}