测验下你的java功底 经验与细节

来源:互联网 发布:淘宝波司登羽绒服反季 编辑:程序博客网 时间:2024/05/12 13:44
package com.j2se;public class WarmingTest {public static void main(String[] args) {// 对于错将=写为==的情况,则该表达式为等号右边的值String str1 = new String("AB");String str2 = new String("ABC");str1 = str1 + 4;// 输出AB4System.out.println(str1);// 输出str2即"ABC"System.out.println(str1 = str2);// 编译可以通过,但运行会出现java.lang.NullPointerException异常// int型数组中的数据初始化为0int[] i1 = new int[10];System.out.println(i1[0]);// boolean型数组中的数据初始化为falseboolean[] b = new boolean[5];System.out.println(b[0]);// 对象型数组中的数据初始化为nullString[] strs = new String[5];System.out.println(strs[1]);// 传递给方法的参数在方法中的改变不会影响该参数Integer ing = new Integer(0);function(ing);// 输出为0System.out.println(ing.intValue());// Byte构造函数中的参数可以是String,如果是int型则必须显式的转换为byte型Byte by = new Byte((byte) 13);System.out.println(by);}static void function(Integer i) {i = new Integer(1);}}


AB4
ABC
0
false
null
0
13


public class CeilAndRoud {public static void main(String[] args) {// Math.ceil表示向上取整 返回12.0System.out.println(Math.ceil(11.2));// Math.floor表示向下取整 返回11.0System.out.println(Math.floor(11.2));// Math.round表示四舍五入 等于Math.floor(11.2+0.5) 返回11System.out.println(Math.round(11.2));// 返回12System.out.println(Math.round(11.5));}}