一、设计思想

从命令行接收多个字,求和后输出。

以两数想加为例,先定义两个字符串,将两个字符串转化为数字,最后输出结果。

二、程序流程图

课后作业01——相加

三、源程序代码

//从命令行接收多个数字,求和 // 两数相加为例

//毛雯雯2015.9.26

package com.minirisoft;

import java.util.Scanner;

public class SumOfNums {

 

    public static void main(String[] args) {

        // TODO Auto-generated method stub

        @SuppressWarnings("resource")

        Scanner sc = new Scanner(System.in);

        System.out.println(" 请输入第一个数字  :  ");

        String z = sc.next();

        System.out.println(" 请输入第二个数字:    ");

        String y = sc.next();

        int a = Integer.parseInt(z);

        int b = Integer.parseInt(y);

        System.out.println(" 两数之和为:    "+(a+b));

    }

四、结果截图课后作业01——相加

 

课后作业01——相加

 课后作业01——相加

相关文章:

猜你喜欢
  • 2021-12-20
  • 2022-12-23
  • 2021-08-18
  • 2022-12-23
  • 2021-09-07
  • 2021-09-16
相关资源
相似解决方案