集册 Java实例教程 使用整数对象添加两个int值

使用整数对象添加两个int值

欢马劈雪     最近更新时间:2020-01-02 10:19:05

447
提示:您可在线编辑运行本教程的实例 - 运行实例,去试试!
使用整数对象添加两个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);


    
展开阅读全文