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

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;
		// 输出AB4
		System.out.println(str1);
		// 输出str2即"ABC"
		System.out.println(str1 = str2);

		// 编译可以通过,但运行会出现java.lang.NullPointerException异常

		// int型数组中的数据初始化为0
		int[] i1 = new int[10];
		System.out.println(i1[0]);

		// boolean型数组中的数据初始化为false
		boolean[] b = new boolean[5];
		System.out.println(b[0]);

		// 对象型数组中的数据初始化为null
		String[] strs = new String[5];
		System.out.println(strs[1]);

		// 传递给方法的参数在方法中的改变不会影响该参数
		Integer ing = new Integer(0);
		function(ing);
		// 输出为0
		System.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.0
		System.out.println(Math.ceil(11.2));
		// Math.floor表示向下取整 返回11.0
		System.out.println(Math.floor(11.2));
		// Math.round表示四舍五入 等于Math.floor(11.2+0.5) 返回11
		System.out.println(Math.round(11.2));
		// 返回12
		System.out.println(Math.round(11.5));
	}
}


  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值