Advertisement
Guest User

Untitled

a guest
Feb 6th, 2016
47
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.03 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class AlphaPos
  4. {
  5. public static void main(String[] args)
  6. {
  7. Scanner kbd = new Scanner(System.in);
  8.  
  9. int position = 0;
  10.  
  11. String alphabet = "abcdefghijklmnopqrstuvwxyz";
  12. String alphabetCAP = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
  13.  
  14. System.out.print("Please enter an upper or lower case letter:");
  15. String letter = kbd.NextLine();
  16.  
  17. char L = letter.charAt(0);
  18.  
  19. if(Character.isLowerCase(L))
  20. {
  21. for(int i = 0 ; i < alphabet.length()-1; i++)
  22. {
  23. if(alphabet.charAt(i) == L)
  24. position = i+1;
  25. }
  26. System.out.print("You entered "+letter+" in upper case it is number "+ position +" in the alphabet.");
  27. }
  28. if(Character.isUpperCase(L))
  29. {
  30. for(int i = 0 ; i < alphabetCAP.length()-1; i++)
  31. {
  32. if(alphabetCAP.charAt(i) == L)
  33. position = i+1;
  34. }
  35. System.out.print(" You entered "+letter+" in upper case it is number "+ position +" in the alphabet.");
  36. }
  37. else
  38. System.out.print(" You entered " +letter+ " and it is no in alphabet.");
  39.  
  40.  
  41. }
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement