提示:您可在线编辑运行本教程的实例 - 运行实例,去试试!
使用整数对象添加两个int值
public class Main { public static Integer add(Integer a, Integer b) { int aValue = a.intValue(); int bValue = b.intValue();/**from NowJava.com - 时代Java**/ int resultValue = aValue + bValue; Integer result = Integer.valueOf(resultValue); return result; } public static void main(String[] args) { int iValue = 2; int jValue = 3; int kValue; /* will hold result as int */ // Box iValue and jValue into Integer objects Integer i = Integer.valueOf(iValue); Integer j = Integer.valueOf(jValue); // Store returned value of the add() method in an Integer object k /* 时代Java公众号 */ Integer k = Main.add(i, j);