Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class AlphaPos
- {
- public static void main(String[] args)
- {
- Scanner kbd = new Scanner(System.in);
- int position = 0;
- String alphabet = "abcdefghijklmnopqrstuvwxyz";
- String alphabetCAP = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
- System.out.print("Please enter an upper or lower case letter:");
- String letter = kbd.NextLine();
- char L = letter.charAt(0);
- if(Character.isLowerCase(L))
- {
- for(int i = 0 ; i < alphabet.length()-1; i++)
- {
- if(alphabet.charAt(i) == L)
- position = i+1;
- }
- System.out.print("You entered "+letter+" in upper case it is number "+ position +" in the alphabet.");
- }
- if(Character.isUpperCase(L))
- {
- for(int i = 0 ; i < alphabetCAP.length()-1; i++)
- {
- if(alphabetCAP.charAt(i) == L)
- position = i+1;
- }
- System.out.print(" You entered "+letter+" in upper case it is number "+ position +" in the alphabet.");
- }
- else
- System.out.print(" You entered " +letter+ " and it is no in alphabet.");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement