📜  Java中的 Scanner locale() 方法及示例

📅  最后修改于: 2022-05-13 01:54:42.666000             🧑  作者: Mango

Java中的 Scanner locale() 方法及示例

Java.util.Scanner类的locale()方法返回此扫描仪的语言环境。

句法:

public Locale locale()

参数:该函数不接受任何参数。

返回值:此函数返回此扫描仪的语言环境

下面的程序说明了上述函数:

方案一:

// 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

方案二:

// 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: Java/util/Scanner.html#locale()