Java - Check if string all upper or lower case letters.
Hi all! Trying to write a small code to check if a string is all upper or lower case letters, such as "JAVA" or "hello", which should return true. If has mixed upper or lower case letters like "SoloLEarn" should return false. I think something is wrong with my logic; I've tried a few different things, like "!" on both conditions or "&&" operator, but my code fails some test cases depending on what I'm trying. Can anyone help? Thanks so much! public static boolean sameCase(String str) { for (char c : str.toCharArray()){ if (!(Character.isUpperCase(c)) || (Character.isLowerCase(c))) return false; } return true; } Here it fails: @Test public void test4() { assertEquals(true, Challenge.sameCase("marmalade")); and @Test public void test7() { assertEquals(true, Challenge.sameCase("pickle")); }