Note that there are some explanatory texts on larger screens.

plurals
  1. POJava String Program
    text
    copied!<p>I'm trying to do a String Program using BufferedReader where you take a String from the user and change the case of the letters. this is what I've got so far:</p> <pre><code>import java.io.*; public class StringProg { public void ff()throws IOException { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); System.out.println("Enter a sentence"); String str=br.readLine(); String s=""; int l=str.length(); char c; for(int a = 1; a &lt; l; a++) { c = str.charAt(a); char d = 0; if(c &gt;= 97 &amp;&amp; c &lt;= 122) { d = c - 32; } else if(c &gt;= 65 &amp;&amp; c &lt;= 90) { d = c + 32; } System.out.print(d); } } } </code></pre> <p>when I run it, it says "possible loss of precision; required char; found int" could someone help me rectify this please?</p> <p>Update: this is the new code after correction:</p> <pre><code>import java.io.*; public class StringProg { public void ff()throws IOException { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); System.out.println("Enter a sentence"); String str=br.readLine(); String s=""; int l=str.length(); char c; char d; for(int a=1;a&lt;l;a++) { c=str.charAt(a); if(c&gt;=97 &amp;&amp; c&lt;=122) { d= (char)(c-32); } else if(c&gt;=65 &amp;&amp;c&lt;=90); { d=(char)(c+32); } System.out.print(d); } } } </code></pre> <p>but the output isn't working.Could someone point out my mistake please? when I enter "a" or "b", there is no output but when I enter "E" it changes to "e", but when I enter "HidE" it changes to 2 squares(I don't know how to print it on the keyboard ) and "e".</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload