题解 | #多组_A+B_零尾模式#

多组_A+B_零尾模式

https://www.nowcoder.com/practice/a561ad77e7bb45679db2bd7317fded84

import java.util.Scanner;

// 注意类名必须为 Main, 不要有任何 package xxx 信息
public class Main {
    public static void main(String[] args) throws Exception {//抛出异常
        Scanner in = new Scanner(System.in);
        while(true){
             String line=in.nextLine();

             if(line.equals("0 0")){
                break;
             }

             String[] numbers=line.split(" ");//将输入的字符串通过空格分隔,存入一个String类型的数组中
             if(numbers.length==2){

                int num1=Integer.parseInt(numbers[0]);//接受String类型的数据,并将其转为int类型
                 int num2=Integer.parseInt(numbers[1]);
                 int sum=num1+num2;
                 System.out.println(sum);
             }else{
                System.out.print("Incorrect input!");
             }


        }//
        in.close();
      


    }
}

全部评论

相关推荐

评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务