Calculator
来源:互联网 发布:严师出高徒知乎 编辑:程序博客网 时间:2024/04/29 06:42
public class Calculator {
/** Main method */
public static void main(String[] args) {
if(args.length != 3) {
System.out.println(
"Usage: java Calculator operand1 operator operand2");
System.exit(0);
}
int operand1 = Integer.parseInt(args[0]);
int operand2 = Integer.parseInt(args[2]);
// The result of the operation
int result = 0;
switch(args[1].charAt(0)) {
case '+': result = operand1 + operand2;break;
case '-': result = operand1 - operand2;break;
case '*': result = operand1 * operand2;break;
case '/': result = operand1 / operand2;break;
}
System.out.println(result);
}
}
/** Main method */
public static void main(String[] args) {
if(args.length != 3) {
System.out.println(
"Usage: java Calculator operand1 operator operand2");
System.exit(0);
}
int operand1 = Integer.parseInt(args[0]);
int operand2 = Integer.parseInt(args[2]);
// The result of the operation
int result = 0;
switch(args[1].charAt(0)) {
case '+': result = operand1 + operand2;break;
case '-': result = operand1 - operand2;break;
case '*': result = operand1 * operand2;break;
case '/': result = operand1 / operand2;break;
}
System.out.println(result);
}
}
java Calculator 5 "*" 9
符号*用于命令行时,表示当前目录下的所有文件。所以,为了明确说明乘法运算符,
命令行中必须用双引号括住符号*。在使用命令java Test * 之后,
下面的程序就会显示当前目录下的所有文件
public class Test {
public static void main(String[] args) {
for(int i = 0; i < args.length; i++)
System.out.println(args[i]);
}
}
0 0
- Calculator
- Calculator
- Calculator
- Calculator
- Calculator
- Calculator
- calculator
- Calculator
- Calculator
- calculator
- Calculator
- Calculator
- Calculator| ||
- Calculator
- Calculator
- Calculator
- MarkSix calculator
- hdu3546 Calculator
- 用户进程间通信主要哪几种方式?
- WPF ListView绑定数据实例
- JS操作剪贴板
- grep简介
- 零基础学习IOS开发(二)- 使用cocos2d-x3.0 运行Hello world
- Calculator
- java Swing 之列表框控件
- 【2014年5月份日常记录表(2014.5.1—5.31,31天)】
- error: stray ‘\343’ in program -------solved
- ubuntu下SVN服务器安装配置
- Oracle 11g 错误:ORA-28002: the password will expire within 7 days 解决方法
- Java基本开发环境搭建
- JavaWeb开发编码系列(五)—— Java的URL编码
- golang 常用库