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.

  1. text.charat(i) returns primitive type char, doesn't have equals method. compare against reference character, use equality operator ==. reference character must surrounded single quotes, not double quotes.

  2. isuppercase must changed isuppercase:

    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

Popular posts from this blog

Fail to load namespace Spring Security http://www.springframework.org/security/tags -

sql - MySQL query optimization using coalesce -

unity3d - Unity local avoidance in user created world -