Java Program to check whether the entered value is ASCII 7-bit control character

Java 8Object Oriented ProgrammingProgramming

<p>To check whether the entered value is ASCII 7-bit control character, check the characters ASCII value before 32 and 127. These are the control characters.</p><p>Here, we have a character.</p><pre class="result notranslate">char one = &#39; n &#39;;</pre><p>Now, we have checked a condition with if-else to check for character less than 32 (ASCII) and equal to 127.</p><pre class="prettyprint notranslate">if (one &lt; 32 || one == 127) { System.out.println(&quot;Given value is a control character!&quot;); } else { &nbsp; &nbsp;System.out.println(&quot;Given value is not a control character!&quot;); }</pre><h2>Example</h2><p><a class="demo" href="http://tpcg.io/yGJXuQ" rel="nofollow" target="_blank">&nbsp;Live Demo</a></p><pre class="prettyprint notranslate">public class Demo { &nbsp; &nbsp;public static void main(String []args) { &nbsp; &nbsp; &nbsp; char one = &#39; &#39;; &nbsp; &nbsp; &nbsp; if (one &lt; 32 || one == 127) { &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;System.out.println(&quot;Given value is a control character!&quot;); &nbsp; &nbsp; &nbsp; } else { &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;System.out.println(&quot;Given value is not a control character!&quot;); &nbsp; &nbsp; &nbsp; } &nbsp; &nbsp;} }</pre><h2>Output</h2><pre class="result notranslate">Given value is a control character!</pre>
raja
Updated on 26-Jun-2020 07:13:37

Advertisements