I'm trying to take a line in single character input and if it's uppercase, switch it to lower case and vice versa.
System.out.print ("Enter character: ");
s=stdin.readLine();
c[i]=s.charAt(0);
k=(int)c[i];
if(k>96)
{
Character.toUpperCase(c[i]);
}
else
{
Character.toLowerCase(c[i]);
}
i++;
}
while(k!=46);
Everything else works right, but that doesn't flip it. HALP
<3
Name:
Anonymous2010-06-18 18:56
String cases = abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ", c = "";
BufferedReader cin = new BufferedReader(new InputStreamReader(System.io));
int i = 0;
do
{
System.out.print("Enter character: ");
try
{
c = "" + (char)cin.read(); // Possible loss of precision?
}
throw(IOException e) { break; }
if((i = cases.indexOf(c)) != -1)
{
c = (i >= 26 ? c.toLowerCase() : c.toUpperCase());
System.out.println(c);
}
}
while(i != -1);
>>5
I can't say I didn't deserve that. Once more, with feeling and proofreading: String cases = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ", c = "";
BufferedReader cin = new BufferedReader(new InputStreamReader(System.io));
int i = 0;
do
{
System.out.print("Enter character: ");
try
{
c = "" + (char)cin.read(); // Possible loss of precision?
}
throw(IOException e) { break; }
if((i = cases.indexOf(c)) != -1)
{
c = (i >= 26 ? c.toLowerCase() : c.toUpperCase());
System.out.println(c);
}
}
while(i != -1);