【发布时间】:2021-11-29 22:26:48
【问题描述】:
所以我搜索了不同的库但找不到它们。 基本上,当用户输入电话号码时,我必须得到一个国家名称。 如输出所示:+1(美国)+92(巴基斯坦)+93(阿富汗)
public static void main(String[] args) throws NumberParseException {
Scanner sc = new Scanner(System.in);
System.out.println("Enter your phone no.:");
String phone = sc.next();
PhoneNumberUtil phoneUtil = PhoneNumberUtil.getInstance();
try{
Phonenumber.PhoneNumber locale = phoneUtil.parse(phone, "");
System.out.println("Country code: " + locale.getCountryCode() );
}
catch(NumberParseException e){
System.err.println("NumberParseException was thrown: " + e.toString());
}
【问题讨论】:
-
查看可用于完成工作的多个库的副本。