char - Simple Java Boolean Not Working -
i have following program goes through string. if there space, print nothing. if char uppercase, print 0. if char lowercase, print 1.
import java.util.*; public class blah { public static void main (string args[]){ scanner input = new scanner(system.in); string text = input.next(); int i; (i = 0; < text.length(); i++) { if (text.charat(i).equals(" ")) system.out.print(" "); else if (character.isuppercase(text.charat(i))) system.out.print("0"); else { system.out.print("1"); } } } }
i following 2 errors:
char cannot deferenced cannot fine symbol: method.isuppercase(char)
please help. thank you.
text.charat(i)
returns primitive typechar
, doesn't haveequals
method. compare against reference character, use equality operator==
. reference character must surrounded single quotes, not double quotes.isuppercase
must changedisuppercase
:for (i = 0; < text.length(); i++) { if (text.charat(i) == ' ') system.out.print(" "); else if (character.isuppercase(text.charat(i))) system.out.print("0"); else { system.out.print("1"); } }
Comments
Post a Comment