Advertisement
Guest User

Untitled

a guest
Nov 22nd, 2017
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.24 KB | None | 0 0
  1. import java.util.*;
  2. import java.io.*;
  3. import java.lang.*;
  4.  
  5. public class dab
  6. {
  7. public static void main(String args[])
  8. {
  9.  
  10. String name = " ";
  11. int yes = 0;
  12. Scanner console = new Scanner(System.in);
  13. int letter = 0;
  14. int digit = 0;
  15. int space = 0;
  16. int special = 0;
  17. char ch;
  18. int i = 0;
  19.  
  20.  
  21. while (yes != 1)
  22. {
  23. try
  24. {
  25. System.out.println("Enter the name of the file");
  26. name = console.nextLine();
  27. Scanner inFile = new Scanner(new FileReader(name));
  28. yes = 1;
  29.  
  30. while(inFile.hasNext())
  31. {
  32. ch = console.next().charAt(i);
  33.  
  34. if (Character.isSpaceChar(ch) == true)
  35. space = space + 1;
  36.  
  37. else if (Character.isDigit(ch) == true)
  38. digit = digit + 1;
  39.  
  40. else if (Character.isLetter(ch) == true)
  41. letter = letter + 1;
  42.  
  43. else
  44. special = special + 1;
  45.  
  46. i++;
  47. }
  48.  
  49.  
  50.  
  51. }
  52. catch (FileNotFoundException error)
  53. {
  54. System.out.println("Error, file not found");
  55. }
  56.  
  57. }
  58.  
  59. console.close();
  60. }
  61.  
  62. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement