Idea : The idea is to create an array, add, but judge whether the minutes and seconds exceed the critical condition of 60, and then output the added data.
import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner a=new Scanner(System.in);
int n=a.nextInt();
while(a.hasNext())
{
int[] A=new int[3]; //创建A数组
int[] B=new int[3]; //创建B数组
int[] num=new int[3]; //创建A+B数组
int s=0,m=0,sort=0;
for(int i=0;i<3;i++) //向数组中添加数据
{
A[i]=a.nextInt();
}
for(int i=0;i<3;i++) //向数组中添加数据
{
B[i]=a.nextInt();
}
for(int i=2;i>=0;i--) //for循环相加
{
if(i==2&&A[i]+B[i]>60) //改行判断的是秒数如果超过60
{
num[i]=A[i]+B[i]-60;
num[i-1]++; //该情况下,向前一位分钟位置+1
sort++; //如果超过60计数器+1
}
else if(i==1&&A[i]+B[i]>60) //该for判断如果分钟超过60
{
num[i]=A[i]+B[i]-60+sort; //相加并减去60,再加上秒数传过来的0
num[i-1]++;
sort=0; //先将计数器归零,是为了防止秒数计数器和分钟计数器混淆
sort++; //这一步是归零后的计数器,分钟超过六十的+1
}
else
num[i]=A[i]+B[i]+sort; //如果都没超过60直接相加
}
for(int i=0;i<3;i++) //输入A+B数据
{
if(i==2)
System.out.print(num[i]);
else
System.out.print(num[i]+" ");
}
System.out.println(); //注意格式
}
}
}
If there is an error, please correct me.