相关疑难解决方法(0)

检查字符是否是Java中的特殊字符

可能重复:
JAVA:检查字符串是否有特殊字符

我是一名新手程序员,正在寻找帮助,确定角色是否是一个特殊角色.我的程序要求用户输入文件名,程序读取文件中的文本并确定文本中有多少空格,数字,字母和特殊字符.我已完成代码以确定空格,数字和字母,但不确定如何检查字符是否是特殊字符.我们对您提供的任何帮助表示赞赏,如果有些问题不够明确,我可以尝试详细说明.到目前为止我的代码是:

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) …
Run Code Online (Sandbox Code Playgroud)

java special-characters

8
推荐指数
2
解决办法
9万
查看次数

标签 统计

java ×1

special-characters ×1