使用了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
- }
-
-
- }