print position of character in alphabet java

Solutions on MaxInterview for print position of character in alphabet java by the best coders in the world

showing results for - "print position of character in alphabet java"
Erika
26 Jun 2016
1import java.util.Scanner;
2
3public class FindPositionOfLetterInAlphabet {
4
5	public static int findPosition(char inputLetter)
6	{
7		// converting input letter in to uniform case. 
8		char inputLetterToLowerCase= Character.toLowerCase(inputLetter);
9		// COnverting chat in to its ascii value
10		int asciiValueOfinputChar= (int)inputLetterToLowerCase;
11		// ASCII value of lower case letters starts from 97
12		int position= asciiValueOfinputChar-96;
13		return position;
14		
15	}
16	public static void main(String[] args) {
17		
18		Scanner sc = new Scanner(System.in);
19        System.out.println("Enter a letter: ");
20        char letter= sc.next().charAt(0);
21        int position= FindPositionOfLetterInAlphabet.findPosition(letter);
22        System.out.println("Position of letter "+letter+" in alphabet is: "+position);
23		
24	}
25}