课后作业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));

    }

四、结果截图

 

 

posted @ 2015-09-26 21:56  justMww  阅读(187)  评论(0)    收藏  举报