输入包含多组数据数据,每组数据占一行,由两个整数A和B组成(-10^9 < A,B < 10^9)。
请计算A+B的结果,并以正常形式输出,每组数据占一行。
-234,567,890 123,456,789 1,234 2,345,678
-111111101 2346912
import java.util.Scanner; public class Main { public static void main(String[] args) { //Java int 类整数的最大值是 2147483647 满足题目条件 Scanner scanner = new Scanner(System.in); System.out.println(getNum(scanner.next())+getNum(scanner.next())); } public static int getNum(String s){ String s1 = s.replace(",", ""); return s1.startsWith("-")?-Integer.parseInt(s1.substring(1)):Integer.parseInt(s1); } }
import java.util.Scanner; public class Main{ /* 不用重复造轮子就是方便啊哈哈 */ public static void main(String[] args){ try(Scanner in = new Scanner(System.in)){ String s1 = in.next(),s2 = in.next(); System.out.println(helper(s1,s2)); } } public static int helper(String s1,String s2){ String[] str1 = s1.split(","),str2 = s2.split(","); StringBuffer sb1 = new StringBuffer(),sb2 = new StringBuffer(); for(String s:str1){ sb1.append(s); } for(String s:str2){ sb2.append(s); } int num1 = Integer.valueOf(sb1.toString()),num2 = Integer.valueOf(sb2.toString()); return num1 + num2; } }
import java.util.Scanner; public class Main{ public static void main(String[] args){ Scanner sc = new Scanner(System.in); while(sc.hasNext()){ String str = sc.nextLine(); String[] str2 = str.split(" "); StringBuilder sa = new StringBuilder(); StringBuilder sb = new StringBuilder(); for(int i=0;i<str2[0].length();i++){ if(str2[0].charAt(i) != ','){ sa.append(str2[0].charAt(i)); } } for(int i=0;i<str2[1].length();i++){ if(str2[1].charAt(i) != ','){ sb.append(str2[1].charAt(i)); } } System.out.println(Integer.valueOf(sa.toString())+Integer.valueOf(sb.toString())); } } }
//无脑的
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class Main {
public static void main(String[] args) throws IOException {
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
String len=null;
while((len=br.readLine())!=null){
String[] str=len.replaceAll(",","").split(" ");
long a=Long.parseLong(str[0]);
long b=Long.parseLong(str[1]);
System.out.println(a+b);
}
br.close();
}
}
/*
* 分享一下,交流一下
*/
import java.util.Scanner;
public class Main{
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
while(in.hasNext()) {
String a = in.next();
String b = in.next();
int A = Integer.parseInt(a.replaceAll(",", ""));
int B = Integer.parseInt(b.replaceAll(",", ""));
System.out.println(A + B);
}
}
}
public class Main {
import java.util.Scanner; public class Main { @SuppressWarnings("resource") public static void main(String[] args) { Scanner scanner = new Scanner(System.in); String next1 = scanner.next(); String next2 = scanner.next(); String[] split1 = next1.split(","); String[] split2 = next2.split(","); StringBuilder stringBuilder1 = new StringBuilder(); for (int i = 0; i < split1.length; i++) { stringBuilder1.append(split1[i]); } StringBuilder stringBuilder2 = new StringBuilder(); for (int i = 0; i < split2.length; i++) { stringBuilder2.append(split2[i]); } System.out.println(Integer.valueOf(stringBuilder1.toString()) + Integer.valueOf(stringBuilder2.toString())); } }
}
import java.util.Scanner;
public class Main{
public static void main(String[] args){
Scanner in=new Scanner(System.in);
while(in.hasNext()){
String a=in.next();
String b=in.next();
System.out.println(Long.valueOf(a.replaceAll(",", ""))+Long.valueOf(b.replaceAll(",", "")));
}
}
}
import java.util.Scanner; public class Main { private static final int MAX=1000; public int add(String str1,String str2){ str1=str1.replace(",", ""); str2=str2.replace(",", ""); int a=Integer.parseInt(str1); int b=Integer.parseInt(str2); return a+b; } public static void main(String[] args){ Main main=new Main(); String str1=new String(); String str2=new String(); int[] count=new int[MAX]; int i=0; Scanner scanner=new Scanner(System.in); while(scanner.hasNext()){ str1=scanner.next(); str2=scanner.next(); count[i]=main.add(str1, str2); i++; } for(int j=0;j<i;j++) System.out.println(count[j]); scanner.close(); } }
这题最好通过valueOf()来做~~
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
while(in.hasNext()){
fun(in.nextLine());
}
in.close();
}
public static void fun(String str){
StringBuffer stra = null,strb = null;
for(int i = 0; i < str.length(); i++){
if(str.charAt(i) == ' '){
stra = new StringBuffer(str.substring(0, i));
strb = new StringBuffer(str.substring(i+1));
break;
}
}
for(int i = 0; i < stra.length(); i++)
if(stra.charAt(i) == ',')
stra.deleteCharAt(i);
for(int i = 0; i < strb.length(); i++)
if(strb.charAt(i) == ',')
strb.deleteCharAt(i);
System.out.println(Long.valueOf(stra.toString())+Long.valueOf(strb.toString()));
}
}