0

我一直试图让java读取“-”以获取电话号码作为用户输入......我知道如何,帮助!

4

2 回答 2

1
String phoneNumber = xxx-xxx-xxx;

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

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

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

    }

}
于 2013-10-22T04:16:19.963 回答
1

尝试

     Scanner scan = new Scanner(System.in);
     System.out.println("Enter the phone no");
     String phoneNo = scan.nextLine();
     System.out.println("Phone No: " + phoneNo);
     scan.close();

输出

Enter the phone no
122-121-121
Phone No: 122-121-121
于 2013-10-22T04:17:57.453 回答