I have a sequence of words in a text file for my project. I'm trying to distinguish the Capital letters from the file, and only print out the biggest number that it can find. for example Input: Roll Tide Roll and my Output: 2 R
I think there is code for finding the max count or something, but I'm lost as of now.
Here is my code I have so far:
import java.io.*;
import java.util.Scanner;
import java.io.IOException;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
public class letters {
public static void main(String[] args) throws FileNotFoundException {
FileInputStream fis = new FileInputStream("input.txt");
Scanner scanner = new Scanner(fis);
String str = scanner.nextLine();
System.out.println(str);
int upperCaseCounter = 0;
int upperCase[] = new int[26];
while (scanner.hasNextLine()) {
String s = scanner.nextLine();
for (int i = 0; i < s.length(); i++) {
char ch = s.charAt(i);
if (Character.isAlphabetic(ch)) {
if (Character.isUpperCase(ch)) {
upperCase[ch - 'A']++;
System.out.println(ch + " : " + upperCase[ch - 'A']);
}
}
}
}
}
}
my output is giving me something on the lines of:
R : 10
O : 6
L : 7
L : 8
R : 11
T : 5
R : 12
I just need to ONLY print the R: 12
How do you go by doing this. Any help would be greatly appreciated. Thanks! I'm new to the indentations on this site and was trying to be quick...