小编Gla*_*L33的帖子

如何检查阵列中是否没有输入字母?

这是一个简单的计算器程序.在我的程序继续"添加"输入的两个参数之前,我只需要检查我的数组并防止其中包含任何字母.输入来自命令行,例如java adder 1 2

public class Adder {
    public static void main(String[] args) {
        //Array to hold the two inputted numbers
        float[] num = new float[2];
        //Sum of the array [2] will be stored in answer
        float answer = 0;

        /*
            some how need to check the type of agruments entered...
        */

        //If more than two agruments are entered, the error message will be shown
        if (args.length > 2 || args.length < 2){
            System.out.println("ERROR: enter only two numbers not …
Run Code Online (Sandbox Code Playgroud)

java command-line calculator

1
推荐指数
1
解决办法
131
查看次数

标签 统计

calculator ×1

command-line ×1

java ×1