Java Math数字处理类与包装类习题
//创建Integer类对象,并以int型返回 Integer intAb = new Integer("123"); System.out.println(intAb.intValue()); //创建两个Character对象,相应转换后判断是否相等 Character charA = new Character('a'); Character charB = new Character('A'); System.out.println("charA = "+charA + " "+"charB = "+charB); System.out.println(charA.equals(charB)); charA = Character.toLowerCase(charA); charB = Character.toLowerCase(charB); System.out.println(charA.equals(charB)); //建立两个Boolean型变量,注意输出 Boolean boolA = new Boolean("true"); Boolean boolB = new Boolean("asd"); Boolean boolC = new Boolean("True"); System.out.println(boolA); System.out.println(boolB); System.out.println(boolC); //输出2~32之间6个偶数的和 int sum = 0; int j = 0; Random ra = new Random(); while(true){ int kk = 2 + ra.nextInt(30); if(kk % 2 == 0){ sum += kk; j++; } if(j == 6) break; } System.out.println(sum); //求园面积 结果保留5位小数 double ymj = Math.PI*Math.pow(2.14, 2); DecimalFormat df1 = new DecimalFormat(); df1.applyPattern(".00000"); System.out.println(df1.format(ymj)); //输出5个四位随机数 String str = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"; for(int k = 0; k < 5; k++){ String strA = ""; for(int i = 1; i <= 4; i++){ Random ran = new Random(); int sui = ran.nextInt(36);//Random 0~36不会包括36的 strA += str.substring(sui,sui+1); } System.out.println(strA); } //使用StringBuilder附加字符串 for(int k = 0; k < 5; k++){ StringBuilder strA = new StringBuilder(); for(int i = 1; i <= 4; i++){ Random ran = new Random(); int sui = ran.nextInt(36);//Random 0~36不会包括36的 strA.append(str.substring(sui,sui+1)); } System.out.println(strA); }