当前位置: 代码迷 >> J2SE >> a+b的处理 新手求好心人帮助,该如何处理
  详细解决方案

a+b的处理 新手求好心人帮助,该如何处理

热度:78   发布时间:2016-04-24 01:08:54.0
a+b的处理 新手求好心人帮助
a+b的处理

------解决方案--------------------
如果a,b是char,byte,short,int,long,float,double类型之一,数值直接相加。

如果a,b其中一个是字符串,会将另一个转换为字符串,进行拼接。

------解决方案--------------------
什么需求?能详细点吗
------解决方案--------------------
Java code
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]);        }    }}
  相关解决方案