JAVA中Math类的random()方法使用

使用了Math类的random()方法, 由于Math类是出于java.lang包(Package),故使用时不必import这个包。

此外本例还使用了移位运算符


/**
 * 使用了Math类的random()方法,
 * 由于Math类是出于java.lang包(Package),故使用时不必import这个包。
 * <p>
 * 此外本例还使用了移位运算符
 * @author HAN
 *
 */
public class Test_random {
	public static void main(String[] args) {
		char ch=(char)('a'+Math.random()*('z'-'a'+1));
		System.out.println(ch);
		
		int a=2;
		System.out.println(a<<7);//移位1位相当于乘以2
	}


}



posted on 2011-12-29 19:54  java课程设计例子  阅读(605)  评论(0编辑  收藏  举报