简体   繁体   English

当我尝试打印字符串时,为什么我的程序打印“ .project”?

[英]Why is it that my program prints “.project” when I try to print a string?

I'm supposed to make a program that inputs three arguments which will later be calculated. 我应该编写一个输入三个参数的程序,稍后再计算这些参数。 The first and third arguments are numbers in string format (ex. "three") while the second argument is the operation (ex. "-" "+"). 第一个和第三个参数是字符串格式的数字(例如“三个”),而第二个参数是运算符(例如“-”“ +”)。 Everything works fine except when I use the "*" operation. 一切正常,除非我使用“ *”操作。 I tried to print the string as it passes the parser function because that's where the error occurs and it prints ".project" instead of the number in string format. 我尝试在通过解析器功能时打印字符串,因为这是发生错误的地方,并且它以字符串格式打印“ .project”而不是数字。

static int converter(String x)
{
    System.out.println(x); 
    int value = 0;
    String zero = "0";
    String one = "1";
    String two = "2";
    String three = "3";
    String four = "4";
    String five = "5";
    String six = "6";
    String seven = "7";
    String eight = "8";
    String nine = "9";
    String ten = "10";
    String eleven = "11";
    String twelve = "12";
    String thirteen = "13";
    String fourteen = "14";
    String fifteen = "15";
    String sixteen = "16";
    String seventeen = "17";
    String eighteen = "18";
    String nineteen = "19";
    String twenty = "20";
    String thirty = "30";
    String forty = "40";
    String fifty = "50";
    String sixty = "60";
    String seventy = "70";
    String eighty = "80";
    String ninety = "90";
    if(x.compareTo("zero")==0)
        value = Integer.parseInt(zero);
    else if(x.compareTo("one")==0)
        value = Integer.parseInt(one);
    else if(x.compareTo("two")==0)
        value = Integer.parseInt(two);
    else if(x.compareTo("three")==0)
        value = Integer.parseInt(three);
    else if(x.compareTo("four")==0)
        value = Integer.parseInt(four);
    else if(x.compareTo("five")==0)
        value = Integer.parseInt(five);
    else if(x.compareTo("six")==0)
        value = Integer.parseInt(six);
    else if(x.compareTo("seven")==0)
        value = Integer.parseInt(seven);
    else if(x.compareTo("eight")==0)
        value = Integer.parseInt(eight);
    else if(x.compareTo("nine")==0)
        value = Integer.parseInt(nine);
    else if(x.compareTo("ten")==0)
        value = Integer.parseInt(ten);
    else if(x.compareTo("eleven")==0)
        value = Integer.parseInt(eleven);
    else if(x.compareTo("twelve")==0)
        value = Integer.parseInt(twelve);
    else if(x.compareTo("thirteen")==0)
        value = Integer.parseInt(thirteen);
    else if(x.compareTo("fourteen")==0)
        value = Integer.parseInt(fourteen);
    else if(x.compareTo("fifteen")==0)
        value = Integer.parseInt(fifteen);
    else if(x.compareTo("sixteen")==0)
        value = Integer.parseInt(sixteen);
    else if(x.compareTo("seventeen")==0)
        value = Integer.parseInt(seventeen);
    else if(x.compareTo("eighteen")==0)
        value = Integer.parseInt(eighteen);
    else if(x.compareTo("nineteen")==0)
        value = Integer.parseInt(nineteen);
    else if(x.compareTo("twenty")==0)
        value = Integer.parseInt(twenty);
    else if(x.compareTo("thirty")==0)
        value = Integer.parseInt(thirty);
    else if(x.compareTo("forty")==0)
        value = Integer.parseInt(forty);
    else if(x.compareTo("fifty")==0)
        value = Integer.parseInt(fifty);
    else if(x.compareTo("sixty")==0)
        value = Integer.parseInt(sixty);
    else if(x.compareTo("seventy")==0)
        value = Integer.parseInt(seventy);
    else if(x.compareTo("eighty")==0)
        value = Integer.parseInt(eighty);
    else if(x.compareTo("ninety")==0)
        value = Integer.parseInt(ninety);
    else { 
        System.out.println("Error.");
        System.exit(0);
    }
    return value;
}

The program runs okay if I enter " * " instead of "*". 如果我输入“ *”而不是“ *”,则程序可以正常运行。

Because when you call your program, the shell expands the wildcard. 因为当您调用程序时,shell会扩展通配符。

Consider the similary between 考虑之间的相似性

dir *.txt

and

java MyProg.class 2 * 3

The asterisk will be replaced by all the files in the directory. 星号将替换为目录中的所有文件。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 当我打印一个字符串值进行控制台打印时,但是当我尝试将此字符串放入双精度String数组时,它返回空 - When I print a string value to console it prints but when i try to put this string in double String array it returns empty 怎么打印'?' 在我尝试打印char(-1)时在Java中 - How can it prints '?' in Java when I try to print char(-1) 当我尝试运行它时,为什么我的程序会冻结/崩溃? - Why does my program freeze/crash when i try to run it? 我怎样才能打印程序? 尝试访问.toString()时收到NullPointerException - How can I get my program to print? I get a NullPointerException when I try to access .toString() 当我尝试破坏活动时,不会留下任何痕迹,为什么我的程序在运行时会退出? - When i try to destroy the activity so no traces will be stay my program just quit when running it why? 当我尝试在 Java 中运行我的套接字程序时,为什么会出现错误? - Why am I getting an error when I try to run my socket program in Java? 当我尝试运行程序时,GUI无法加载,我无法弄清楚为什么 - When i try to run my program, the GUI won't load and I can't figure out why 为什么当我尝试打印实体时java.lang.StackOverflowError:null - Why java.lang.StackOverflowError: null when I try to print my entity 当我尝试无休止地更新JTextField时,为什么程序会冻结? - Why does my program freeze when I try to update a JTextField with an endless while? 当我尝试添加ArrayList元素时,即使它是新的,为什么我的程序仍然存在? - Why does my program say the ArrayList element exists when I try to add it even though it's new?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM