Java Program to check whether the entered value is ASCII 7 bit alphabetic

Java 8Object Oriented ProgrammingProgramming

<p>To check whether the entered value is ASCII 7-bit alphabetic, check the character from &lsquo;a&rsquo; to &lsquo;z&rsquo; or &lsquo;A&rsquo; to &lsquo;Z&rsquo;.</p><p>Here, we have a character.</p><pre class="result notranslate">char one = &#39;r&#39;;</pre><p>Now, we have checked a condition with if-else to check for character from &lsquo;a&rsquo; to &lsquo;z&rsquo; or &lsquo;A&rsquo; to &lsquo;Z&rsquo;.</p><pre class="prettyprint notranslate">if ((one &gt;= &#39;A&#39; &amp;&amp; one &lt;= &#39;Z&#39;) || (one &gt;= &#39;a&#39; &amp;&amp; one &lt;= &#39;z&#39;)) { &nbsp; &nbsp;System.out.println(&quot;Given value is an alphabet!&quot;); } else { &nbsp; &nbsp;System.out.println(&quot;Given value is not an alphabet!&quot;); }</pre><h2>Example</h2><p><a class="demo" href="http://tpcg.io/dquPDk" rel="nofollow" target="_blank">&nbsp;Live Demo</a></p><pre class="prettyprint notranslate" style="margin-left: 20px;">public class Demo { &nbsp; &nbsp;public static void main(String []args) { &nbsp; &nbsp; &nbsp; char one = &#39;r&#39;; &nbsp; &nbsp; &nbsp; System.out.println(&quot;Character: &quot;+one); &nbsp; &nbsp; &nbsp; if ((one &gt;= &#39;A&#39; &amp;&amp; one &lt;= &#39;Z&#39;) || (one &gt;= &#39;a&#39; &amp;&amp; one &lt;= &#39;z&#39;)) { &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;System.out.println(&quot;Given value is an alphabet!&quot;); &nbsp; &nbsp; &nbsp; } else { &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;System.out.println(&quot;Given value is not an alphabet!&quot;); &nbsp; &nbsp; &nbsp; } &nbsp; &nbsp;} }</pre><h2>Output</h2><pre class="result notranslate">Character: r Given value is an alphabet!</pre><p>Let us see another example</p><h2>Example</h2><p><a class="demo" href="http://tpcg.io/WKjNJz" 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;1&#39;; &nbsp; &nbsp; &nbsp; System.out.println(&quot;Character: &quot;+one); &nbsp; &nbsp; &nbsp; if ((one &gt;= &#39;A&#39; &amp;&amp; one &lt;= &#39;Z&#39;) || (one &gt;= &#39;a&#39; &amp;&amp; one &lt;= &#39;z&#39;)) { &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;System.out.println(&quot;Given value is an alphabet!&quot;); &nbsp; &nbsp; &nbsp; } else { &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;System.out.println(&quot;Given value is not an alphabet!&quot;); &nbsp; &nbsp; &nbsp; } &nbsp; &nbsp;} }</pre><h2>Output</h2><pre class="result notranslate">Character: 1 Given value is not an alphabet!</pre>
raja
Updated on 26-Jun-2020 07:16:35

Advertisements