Java Scanner locale()方法及示例
java.util.Scanner 类的 locale() 方法返回该扫描仪的locale。
语法
public Locale locale()
参数: 该函数不接受任何参数。
返回值: 该函数返回该 扫描仪的locale 。
下面的程序说明了上述函数。
程序1 :
// Java program to illustrate the// locale() method of Scanner class in Java// without parameter import java.util.*; public class GFG1 { public static void main(String[] argv) throws Exception { String s = "Gfg Geeks GeeksForGeeks"; // create a new scanner // with the specified String Object Scanner scanner = new Scanner(s); // print the locale System.out.println(scanner.locale()); scanner.close(); }}
输出:
en_US
程序2
// Java program to illustrate the// locale() method of Scanner class in Java// without parameter import java.util.*; public class GFG1 { public static void main(String[] argv) throws Exception { String s = "121324"; // create a new scanner // with the specified String Object Scanner scanner = new Scanner(s); // print the locale System.out.println(scanner.locale()); scanner.close(); }}输出:
en_US
**参考资料: ** https://docs.oracle.com/javase/7/docs/api/java/util/Scanner.html#locale()
