Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.*;
- public class kap4_selfCheck24{
- public static void main(String[] args){
- Scanner console = new Scanner(System.in);
- System.out.print("Write some text here: ");
- String text = console.nextLine();
- // converts the string into a char array with only lowercase characters
- char[] chars = text.toLowerCase().toCharArray();
- // our total number of characters in second half of alphabet, we'll add to this in an forloop ;)
- int total = 0;
- for(int i = 0; i<=chars.length-1; i++){
- // Checks if char is between the value of 110 and 122 which are N and Z
- // Source of the numbers 110 and 122: http://paulschou.com/tools/xlate/
- if(chars[i]>=110&&chars[i]<=122){
- total++;
- }
- }
- System.out.println("There are "+total+" characters from the second half of the alphabet, in the text that you wrote.");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement