算法竞赛入门经典的java实现之小学生算术->Demo26.java
下面贴出源码:
package cn.zimo.algorithm;
import java.util.Scanner;
/**
* 小学生算术
* @author 子墨
* @date 2018年5月5日 下午9:14:54
*/
public class Demo26 {
public static void main(String[] args) {
Scanner scanner=new Scanner(System.in);
String temp=new String();
temp=scanner.nextLine();
while(!temp.startsWith("0")) {
String[] s=temp.split(" ");
int a=Integer.parseInt(s[0]);
int b=Integer.parseInt(s[1]);
if(a==0&&b==0) {
return;
}
int c=0,ans=0;
for(int i=9;i>=0;i--) {
c=(a%10+b%10+c)>9?1:0;
ans+=c;
a/=10;
b/=10;
}
System.out.print("\n"+ans);
temp=scanner.nextLine();
//System.out.println();
}
}
}