Anda di halaman 1dari 2

package MakeSeleniumEasy;

import java.util.Scanner;

public class FindPositionOfLetterInAlphabet {

public static int findPosition(char inputLetter)


{
// converting input letter in to uniform case.
char inputLetterToLowerCase= Character.toLowerCase(inputLetter);
// COnverting chat in to its ascii value
int asciiValueOfinputChar= (int)inputLetterToLowerCase;
// ASCII value of lower case letters starts from 97
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);

}
}
public class Exercise19 {

public static void main(String[] args)


{
String str = "The quick brown fox jumps over the lazy dog.";

// Get the index of all the characters of the alphabet


// starting from the beginning of the String.
int a = str.indexOf("a", 1);
int b = str.indexOf("b", 2);
int c = str.indexOf("c", 3);
int d = str.indexOf("d", 4);
int e = str.indexOf("e", 5);
int f = str.indexOf("f", 6);
int g = str.indexOf("g", 7);
int h = str.indexOf("h", 8);
int i = str.indexOf("i", 9);
int j = str.indexOf("j", 10);
int k = str.indexOf("k", 11);
int l = str.indexOf("l", 12);
int m = str.indexOf("m", 13);
int n = str.indexOf("n", 14);
int o = str.indexOf("o", 15);
int p = str.indexOf("p", 16);
int q = str.indexOf("q", 17);
int r = str.indexOf("r", 18);
int s = str.indexOf("s", 19);
int t = str.indexOf("t", 20);
int u = str.indexOf("u", 21);
int v = str.indexOf("v", 22);
int w = str.indexOf("w", 23);
int x = str.indexOf("x", 24);
int y = str.indexOf("y", 25);
int z = str.indexOf("z", 26);

// Display the results of all the indexOf method calls.


System.out.println(" a b c d e f g h i j");
System.out.println("=========================");
System.out.println(a + " " + b + " " + c + " " + d + " " +
e + " " + f + " " + g + " " + h + " " +
i + " " + j + "\n");

System.out.println("k l m n o p q r s t");
System.out.println("===========================");
System.out.println(k + " " + l + " " + m + " " + n + " " +
o + " " + p + " " + q + " " + r + " " +
s + " " + t + "\n");

System.out.println("u v w x y z");
System.out.println("================");
System.out.println(u + " " + v + " " + w + " " + x + " " +
y + " " + z);
}
}

Anda mungkin juga menyukai