算法竞赛入门经典的java实现之小学生算术->Demo26.java

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/qq_36737934/article/details/80211998

下面贴出源码:

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();
        }
        
    }
}


猜你喜欢

转载自blog.csdn.net/qq_36737934/article/details/80211998