Skip to content

Instantly share code, notes, and snippets.

@andymuncey
Last active October 19, 2021 10:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save andymuncey/c86f0d47726376513dca91270493b0b9 to your computer and use it in GitHub Desktop.
Save andymuncey/c86f0d47726376513dca91270493b0b9 to your computer and use it in GitHub Desktop.
Check if a character in a string is uppercase or lowercase
java.util.Scanner scanner = new java.util.Scanner(System.in);
System.out.println("Type a String");
String text = scanner.nextLine();
System.out.println("Type the index of the position");
int index = scanner.nextInt();
scanner.nextLine();
if (index >= 0 && index < text.length()) {
char letter = text.charAt(index);
if (Character.isUpperCase(letter)){
System.out.println("Uppercase");
} else if (Character.isLowerCase(letter)){
System.out.println("Lowercase");
} else {
System.out.println("Neither upper or lowercase");
}
} else {
System.out.println("Not a valid index in the String");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment