Write a method 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.

Respuesta :

Answer:

The answer to this question can be given as:

Method Definition:

public static int secondHalfLetters(String letters)

{

int count = 0;

for (int i = 0; i < letters.length(); i++)

{

if (Character.toLowerCase(letters.charAt(i)) >= 'n')

{

count++;

}

}

return count;

}

Explanation:

In the above method definition first we declare the method that name is already given in the question that is secondHalfLetters() function. In this function we pass a string parameter that is letters.In the function we declare  an integer variable count.Then we declare the for loop. In this loop we declare the conditional statement in the if block we convert character into lowercase and check that value is greater the equal to n. If this condition is true then it count increase by 1. In the lass we return count value.