• 9. Write a program that reads a file one character at a time and prints out how many characters are uppercase letters,
-
- Site Admin
- Posts: 899603
- Joined: Mon Aug 02, 2021 8:13 am
• 9. Write a program that reads a file one character at a time and prints out how many characters are uppercase letters,
• 9. Write a program that reads a file one character at a time and prints out how many characters are uppercase letters, lowercase letters, digits, white space, and something else. Characters.java 1 import java.io.File; 2 import java.io.FileNotFoundException; 3 import java.io.PrintWriter; 4 import java.util.Scanner; 5 6 public class Characters 7 { 8 public static void main(String[] args) throws FileNotFoundException 9 { 10 Scanner console = new Scanner(System.in); 11 System.out.print("Input file: "); 12 String inputFileName = console.next(); 13 int uppercase = 0; 14 int lowercase = 0; 15 int digits = 0; 16 int whitespace = 0; 17 int other = 0; 18 19 while (...) 20 { 21 22 if (. ..) { uppercase++; } 23 else if (...) { lowercase++; } 24 else if (...) { digits++; } 25 else if (...) { whitespace++; } 26 else other++; 27 } 28 29 System.out.println("Uppercase: " + uppercase); 30 System.out.println("Lowercase: + lowercase); 31 System.out.println("Digits: " + digits); 32 System.out.println("Whitespace: + whitespace); 33 System.out.println("Other: " + other); 34 } 35} 11