首页 > 其他 > 详细

字符串的运算

时间:2017-10-08 00:05:00      阅读:265      评论:0      收藏:0      [点我收藏+]

设计思想

先以字符串的形式接收数据,然后强转成整形进行运算

程序流程图

技术分享

程序源码

import java.util.Scanner;
public class Addition {
public static void main( String args[] )
{
Scanner scanner=new Scanner (System.in);
String firstNumber, // first string entered by user
secondNumber; // second string entered by user
int number1, // first number to add
number2, // second number to add
sum; // sum of number1 and number2
// read in first number from user as a string
System.out.println("请输入第一个数:");
firstNumber=scanner.next();
// read in second number from user as a string
System.out.println("请输入第二个数:");
secondNumber =scanner.next();

// convert numbers from type String to type int
number1 = Integer.parseInt( firstNumber );
number2 = Integer.parseInt( secondNumber );

// add the numbers
sum = number1 + number2;
System.out.println("和为:"+sum);
System.exit( 0 ); // terminate the program
}
}

运行结果

技术分享

 

字符串的运算

原文:http://www.cnblogs.com/wei-jing/p/7636231.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!