Untitled
unknown
java
3 years ago
1.2 kB
3
Indexable
package Labs.Assignment4.PartTwo;
import java.util.*;
public class QuestionFourPointFifteen
{
public static void main(String[] args)
{
/// Prompt user to enter letter than convert letter into uppercase
Scanner scanner = new Scanner(System.in);
System.out.println("Please enter a letter: ");
char letter = scanner.next().toUpperCase().charAt(0);
int ascii = letter;
scanner.close();
/*Check if character is a letter than provide the corrsepending number if so otherwise
return invalid input statement */
int number = 0;
if (Character.isLetter(ascii))
{
if (ascii <=90 && ascii > 86)
number = 9;
else if (ascii <= 86 && ascii > 83)
number = 8;
else if (ascii <= 83 && ascii > 79)
number = 7;
else if (ascii <= 79 && ascii > 76)
number = 6;
else if (ascii <= 76 && ascii > 73)
number = 5;
else if (ascii <= 73 && ascii > 70)
number = 4;
else if (ascii <= 70 && ascii > 67)
number = 3;
else if (ascii <= 67 && ascii >=65)
number = 2;
System.out.println("The corresponding number is " + number);
}
else
System.out.println(letter + " is an invalid input");
}
}
Editor is loading...