how to give a letter's position in the alphabet in java code example
Example: print position of character in alphabet java
import java.util.Scanner;
public class FindPositionOfLetterInAlphabet {
public static int findPosition(char inputLetter)
{
char inputLetterToLowerCase= Character.toLowerCase(inputLetter);
int asciiValueOfinputChar= (int)inputLetterToLowerCase;
int position= asciiValueOfinputChar-96;
return position;
}
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter a letter: ");
char letter= sc.next().charAt(0);
int position= FindPositionOfLetterInAlphabet.findPosition(letter);
System.out.println("Position of letter "+letter+" in alphabet is: "+position);
}
}