a+b的处理

解决方案 »

  1.   

    如果a,b是char,byte,short,int,long,float,double类型之一,数值直接相加。如果a,b其中一个是字符串,会将另一个转换为字符串,进行拼接。
      

  2.   

    比如说a+b多组数据的处理计算A+B输入数据有多组。每组一行,为整数A, B。以EOF做结束。
    输出A+B的值。样例输入
    1 2
    3 4
    样例输出
    3
    7计算A+B输入输入第1行为一个整数n(1≤n≤10),代表测试的组数。
    下面有n组测试数据,每组1行,为2个整数,为A, B。输出输出A+B的值。样例输入2
    1 2
    3 4样例输出3
    7
      

  3.   

    就是比如遇到c语言那样类似
    a+b多组数据应该怎么处理的?
      

  4.   

    public class Test {
    public static void main(String args[]) {
    Scanner input = new Scanner(System.in);
    int[][] ops = null;
    boolean flag = true;
    int countTest = 0;
    while (flag) {
    System.out.print("多少组测试数据:\n");
    try {
    countTest = input.nextInt();
    ops = new int[countTest][3];
    } catch (Exception e) {
    // e.printStackTrace();
    continue;
    }
    flag = false;
    }
    System.out.print("请输入数据:\n");

    for(int index = 0;index<countTest*2; index++ ){
    ops[index/2][index%2] = input.nextInt();
    if((index+1)%2 == 0){
    ops[(index-1)/2][2] = ops[(index-1)/2][0]+ops[(index-1)/2][1];
    }
    }
    for(int index = 0;index<countTest;index++){
    System.out.println(ops[index][2]);
    }
    }
    }