Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/jenkins/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java:如何阅读-&引用;在用户int输入中_Java_Input_Int - Fatal编程技术网

Java:如何阅读-&引用;在用户int输入中

Java:如何阅读-&引用;在用户int输入中,java,input,int,Java,Input,Int,我一直在尝试让java读取“-”,以便将电话号码作为用户输入。。。Idk如何,救命 String phoneNumber=xxx xxx; String phoneNumber = xxx-xxx-xxx; for(int i = 0;i<phoneNumber.length();i++){ if(phoneNumber[i] == '-') { System.out.println(phoneNumber[i]); } } 对于(inti

我一直在尝试让java读取“-”,以便将电话号码作为用户输入。。。Idk如何,救命

String phoneNumber=xxx xxx;
String phoneNumber = xxx-xxx-xxx;

for(int i = 0;i<phoneNumber.length();i++){

   if(phoneNumber[i] == '-')

    {
        System.out.println(phoneNumber[i]);

    }

}
对于(inti=0;itry

输出

Enter the phone no
122-121-121
Phone No: 122-121-121

我们可以看到您一直在使用的代码吗?您应该将其作为
字符串读取,然后从那里进行解析…将用户输入作为字符串读取并拆分-然后将其转换为int String str=“st1-st2-st3”;String delimiter=“-”,String[]temp;temp=str.split(delimiter);for(int i=0;iEnter the phone no
122-121-121
Phone No: 122-121-121