Java Character.isISOControl(char)方法

原文:https://www.studytonight.com/java-wrapper-class/java-character-isisocontrolchar-ch-method

Java isISOControl(char ch)Character 类的一部分。此方法用于检查指定字符是否为国际标准化组织控制字符。

如果一个字符的代码在'\u000''\u001F'的范围内或者在'\u007F''\u009F'的范围内,则该字符是一个 ISO 控制字符。

语法:

public static boolean isISOControl(char ch)

参数:

传递的参数是要检查国际标准化组织控制的字符。

返回:

如果指定字符是国际标准化组织控制字符,返回布尔值true,否则返回false

例 1:

这里,通过使用 isISOControl()方法检查字符是否是 ISO 控制字符。

public class StudyTonight
{  
    public static void main(String[] args)
    {  
        char ch1 = 'g';  
        char ch2 = 'D';  
        char ch3 = '#';  
        char ch4  = 'e';   
        char ch5  = '8';  

        boolean b1 = Character.isISOControl(ch1);  
        boolean b2 = Character.isISOControl(ch2);  
        boolean b3 = Character.isISOControl(ch3);  
        boolean b4 = Character.isISOControl(ch4);  
        boolean b5 = Character.isISOControl(ch5);  

        System.out.println(ch1 +" is a ISO control?:  "+b1);  
        System.out.println(ch2 +" is a ISO control?:  "+b2);  
        System.out.println(ch3 +" is a ISO control?:  "+b3);  
        System.out.println(ch4 +" is a ISO control? : "+b4);  
        System.out.println(ch5 +" is a ISO control?:  "+b5);  
    }  
}

g 是 ISO 对照?:假 D 是 ISO 质控品?:假

是 ISO 质控吗?:假

e 是 ISO 质控品?:假 8 是 ISO 质控品?:假

例 2:

这里有一个用户定义的例子,任何使用这段代码的人都可以输入自己选择的值,并获得等效的输出。

import java.util.Scanner; 
public class StudyTonight
{ 
    public static void main(String[] args)
    {  
        try
        {
            System.out.print("Enter the character: ");  
            Scanner sc = new Scanner(System.in);         
            char ch = sc.next().charAt(0);  
            boolean b = Character.isISOControl(ch);
            System.out.println(ch + " is an ISO Control? : "+b);
        }
        catch(Exception e)
        {
            System.out.println("Invalid Input!!");
        }
    }  
}

输入字符:~ ~是 ISO 控件吗?:false *输入字符:。 。是国际标准化组织的控制?:假

实时示例:

在这里,您可以测试实时代码示例。您可以为不同的值执行示例,甚至可以编辑和编写您的示例来测试 Java 代码。