// Stores the count of A to Z. letterCount [ 26 ] is the // count of any characters that is not in the alphabet. int[] letterCount = new int [ 27 ]; // Init our array. for ( int i = 0; i < letterCount.length; i++ ) letterCount [ i ] = 0; while (inputStream.hasNextLine()) { next = inputStream.nextLine(); // Loop through the sentence. for ( int i = 0; i < next.length(); i++ ) { // Grab a character from the sentence, make sure it is uppercase // so we can count accurately. char c = next.toUpperCase().charAt ( i ); // Hack: Cheap way to get the ascii equivalent of the character. int ascii = c - 65; // Check if it is a valid letter ( A - Z ). if ( ascii >= 0 || ascii <= 25 ) { // Increment the count. letterCount [ ascii ]++; } else { // Not an alphabet. letterCount [ 26 ]++; } } // Change to uppercase or lowercase as indicated. outputStream.println( ( choice.toLowerCase().equals ( "y" ) ) ? next.toUpperCase() : next.toLowerCase() ); }