Real title : Cannot convert char to boolean!
Hello.
This code is meant to be able to take any text and count the uppercase letters, lowercase letters, whitespaces and digits (well not really digits but the other characters that are not letters or whitespaces).
However it seem like i cannot check for up/low case letters by my if statements.
Any ideas?
import java.io.BufferedReader; import java.io.FileNotFoundException; import java.io.FileReader; import java.io.IOException; public class RaknaTecken { private static int upCase = 0; private static int lowCase = 0; private static int digit = 0; private static int whitespace = 0; public static void main(String[] args) throws IOException { check(); } private static void check() throws IOException { System.out.println( "This program checks for different types of letters (upper and lower case), whitespaces and characters.\n"); String call = "C:\\Users\\karwa\\Desktop\\kq.txt"; FileReader file = new FileReader(call); BufferedReader reading = new BufferedReader(file); System.out.println("Reads file from : " + call + ".\n"); try { for (char c : reading.readLine().toCharArray()) { if (Character.toUpperCase(c)) { //Here is the first error. upCase++; } else if (Character.toLowerCase(c)) { //Here is the second error. lowCase++; } else if (Character.isDigit(c)) { digit++; } else if (Character.isWhitespace(c)) { whitespace++; } } } catch (Exception e) { System.out.println("Error : " + e.getMessage()); } System.out.printf("The text file contains : %d upCase, %d lowCase, %d digit, and %d whitespace characters.\n", upCase, lowCase, digit, whitespace); } }
Also i know that i have a try/catch and IOException but just playing around with those two atm.
Here is the error:
Exception in thread "main" java.lang.Error: Unresolved compilation problems: Type mismatch: cannot convert from char to boolean Type mismatch: cannot convert from char to boolean at km222nb_lab4.RaknaTecken.check(RaknaTecken.java:28) at km222nb_lab4.RaknaTecken.main(RaknaTecken.java:16)