Advertisement
Guest User

Untitled

a guest
Sep 16th, 2014
175
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.95 KB | None | 0 0
  1. import java.util.*;
  2.  
  3. public class kap4_selfCheck24{
  4.    public static void main(String[] args){
  5.       Scanner console = new Scanner(System.in);
  6.  
  7.       System.out.print("Write some text here: ");
  8.       String text = console.nextLine();
  9.      
  10.       // converts the string into a char array with only lowercase characters
  11.       char[] chars  = text.toLowerCase().toCharArray();
  12.      
  13.       // our total number of characters in second half of alphabet, we'll add to this in an forloop ;)
  14.       int total = 0;
  15.          
  16.       for(int i = 0; i<=chars.length-1; i++){
  17.          // Checks if char is between the value of 110 and 122 which are N and Z
  18.          // Source of the numbers 110 and 122: http://paulschou.com/tools/xlate/
  19.          if(chars[i]>=110&&chars[i]<=122){
  20.             total++;
  21.          }
  22.       }
  23.      
  24.       System.out.println("There are "+total+" characters from the second half of the alphabet, in the text that you wrote.");
  25.    }
  26. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement