-
-
Save andymuncey/c86f0d47726376513dca91270493b0b9 to your computer and use it in GitHub Desktop.
Check if a character in a string is uppercase or lowercase
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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