Note that there are some explanatory texts on larger screens.

plurals
  1. POChecking if a character is a special character in Java
    primarykey
    data
    text
    <blockquote> <p><strong>Possible Duplicate:</strong><br> <a href="https://stackoverflow.com/questions/1795402/java-check-a-string-if-there-is-a-special-character-in-it">JAVA: check a string if there is a special character in it</a> </p> </blockquote> <p>I am a novice programmer and am looking for help determining if a character is a special character. My program asks the user to input the name of a file, and the program reads the text in the file and determines how many blanks spaces, digits, letters, and special characters are in the text. I have the code completed to determine the blanks, digits, and letters, however am unsure of how to check if a character is a special character. Any help you can offer is appreciated and if something was not clear enough I can try to elaborate. My code so far is: </p> <pre><code>import java.util.Scanner; import java.io.*; public class TextFile{ public static void main(String[] args){ Scanner input = new Scanner (System.in); String fileName; boolean goodName = false; int blankCount = 0; int letterCount = 0; int digitCount = 0; int specialcharCount = 0; String currentLine; char c; Scanner lineFile= null; FileReader infile; System.out.println("Please enter the name of the file: "); fileName = input.nextLine(); while (!goodName) { try{ infile = new FileReader(fileName); lineFile = new Scanner(infile); goodName= true; } catch(IOException e) { System.out.println("Invalid file name, please enter correct file name: "); fileName=input.nextLine(); } } while (lineFile.hasNextLine()){ currentLine = lineFile.nextLine(); for(int j=0; j&lt;currentLine.length();j++){ c=currentLine.charAt(j); if(c== ' ') blankCount++; if(Character.isDigit(c)) digitCount++; if(Character.isLetter(c)) letterCount++; if() specialcharCount++; } } } } </code></pre> <p>I need something to put in the if statement at the end to increment specialcharCount. </p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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