Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a method in java named secondHalfLetters that accepts a string as its para

ID: 3554378 • Letter: W

Question

Write a method in java named secondHalfLetters that accepts a string as its parameter and returns an integer representing how many of letters in the string come from the second half of the alphabet (that is, have values of 'n' through 'z' inclusive). Compare case-insensitively, such that uppercase values of 'N' through 'Z' also count. For example, the call secondHalfLetters("ruminates") should return 5 because the 'r', 'u', 'n', 't', and 's' come from the second half of the alphabet. You may assume that every character in the string is a letter.

Explanation / Answer

public static int secondHalfLetters( String s)
   {
      
       s = s.toLowerCase() ;
       int res = 0 ;
       for(int i = 0 ; i < s.length() ; i++ )
       if( s.charAt(i) >= 'n' && s.charAt(i) <= 'z' )
       res++ ;
      
       return res ;
   }