StringBuffer 1public class Demo {2 public static void main(String[] args) {3 StringBuffer buf = new StringBuffer();4 for(int x = 'a'; x <'z'; x ++){5 buf.append((char) x);6 }7 buf.reverse().delete(0, 5);8 System.out.println(buf);9 }10} 随机数组 1package cn.cccc.demo;2import java.util.Arrays;3import java.util.Random;4class NumberFactory{5 private static Random random = new Random();6 7 public static int [] create(int len ){8 int data [] = new int [len];9 int foot = 0;10 while(foot < data.length){11 int num = random.nextInt(30);12 data[foot++] = num;13 }14 return data;15 }7 collapsed lines16}17public class Demo {18 public static void main(String[] args) {19 int result [] = NumberFactory.create(5);20 System.out.println(Arrays.toString(result));21 }22} 抛硬币检测 1package cn.cccc.demo;2import java.util.Arrays;3import java.util.Random;4class Coin {5 private static Random random = new Random();6 private int front;7 private int back;8 public void throwCoin(int count){9 for(int x= 0; x < count ; x++){10 int side = random.nextInt(2);11 if(side == 0 ){12 this.front++;13 }else {14 this.back++;15 }16 collapsed lines16 }17 }18 public int getFront(){19 return this.front;20 }21 public int getBack(){22 return this.back;23 }24}25public class Demo {26 public static void main(String[] args) {27 Coin coin = new Coin();28 coin.throwCoin(1000);29 System.out.println("正面的次数"+coin.getFront()+",背面的次数"+coin.getBack());30 }31}