小学生算术
时间限制:3000 ms | 内存限制:65535 KB
难度:1
-
描述
- 很多小学生在学习加法时,发现“进位”特别容易出错。你的任务是计算两个三位数在相加时需要多少次进位。你编制的程序应当可以连续处理多组数据,直到读到两个0(这是输入结束标记)。
-
输入
- 输入两个正整数m,n.(m,n,都是三位数) 输出
- 输出m,n,相加时需要进位多少次。 样例输入
-
123 456 555 555 123 594 0 0
样例输出 -
0 3 1
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scanner=new Scanner(System.in);
int a=scanner.nextInt();
int b=scanner.nextInt();
while(a!=0 || b!=0)
{
int []num1=new int[3];
int []num2=new int[3];
int flag=0,count=0;
num1[0]=a%10;
num1[1]=a/10%10;
num1[2]=a/100;
num2[0]=b%10;
num2[1]=b/10%10;
num2[2]=b/100;
if(num1[0]+num2[0]>9)
{
flag=1;
count++;
}
if(num1[1]+num2[1]+flag>9)
{
flag=1;
count++;
}
else
{
flag=0;
}
if(num1[2]+num2[2]+flag>9)
{
count++;
}
System.out.println(count);
a=scanner.nextInt();
b=scanner.nextInt();
}
}
}