如何为计算器创建命令行参数

时间:2015-11-03 04:07:26

标签: java

我不确定如何为计算器创建命令行参数,任何帮助?到目前为止,这是我的代码。我被要求做的问题是代码中的块注释。

import java.util.Scanner;
public class M93 {


public static void main(String[] args) {

/* A simple calculator program is expecting command line arguments that have the form <operand1> <operator> <operand> where both <operand1> and <operand2> 
are integers while <operator> is one of +, -, *, /, or %. Write a method that will calculate and return the value of <operand1> <operator> <operand2>. 
For example, if the command line arguments are 5 + 3, the method should return the value 8. Assume that the command line argument values are all valid.
*/
String s = new String[5];
operator[0] = "+";
operator[1] = "-";
operator[2] = "*";
operator[3] = "/";
operator[4] = "%";
String inputOperator;
int a, b;
Scanner scanner = new Scanner(System.in);    
System.out.println("Calculator: " + scanner.nextInt() );

}

public static int addition(int a, int b, int answer) {

answer = (a + b);
System.out.println(answer);
return answer;

}

}

1 个答案:

答案 0 :(得分:2)

您不必使用set.seed(24) df <- as.data.frame(matrix( sample(c(NA, 0:5), 10*10, replace=TRUE), ncol=10))

运行您的程序,如:

  

java ClassName 2 3 +

Scanner