java - How to print out just the max number from a list of an array? -


i have sequence of words in text file project. i'm trying distinguish capital letters file, , print out biggest number can find. example input: roll tide roll , output: 2 r

i think there code finding max count or something, i'm lost of now.

here code have 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();          (int = 0; < 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 giving me on lines of:

r : 10 o : 6 l : 7 l : 8 r : 11 t : 5 r : 12 

i need print r: 12

how go doing this. appreciated. thanks! i'm new indentations on site , trying quick...

you can use of arrays#sort method find max or min number in array.

arrays.sort(uppercase); int maxindex = uppercase.length-1; system.out.println("max element is:"+(char)uppercase[maxindex])+":"+uppercase[maxindex]);   

sort() method sorts array in ascending order.then first element of array min number , last element of array max.

note : above code should after while loop prints 1 time instead of multiple times in case.


Comments

Popular posts from this blog

html - How to style widget with post count different than without post count -

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

javascript - storing input from prompt in array and displaying the array -