View Single Post
 
Reply
Posted 2010-02-26, 05:12 AM in reply to Lenny's post starting "No need to put them into an array - you..."
I've had a look at the API, and I can't see another way to do it. I made a small mistake above - you can't tack .equals on the end of a char. Instead, get the first char using charAt and add it to a string, then return the result of the comparison.

This is very simple, so I have no qualms in giving you the code, but when you get to more complex things I'll just give you a push in the right direction.

Code:
public class CheckCharCase {

	public static void main(String[] args) {
		System.out.println("" + getFirst("Hello"));	//true
		System.out.println("" + getFirst("hello"));	//false
		System.out.println("" + getSecond("Hello"));	//true
		System.out.println("" + getSecond("HEllo"));	//false
	}

	private static boolean getFirst(String s) {
		String str = "" + s.charAt(0);
			//get the first char of the string, put into a string
		return(str.equals(str.toUpperCase()));
			//compare and return
	}
	
	private static boolean getSecond(String s) {
		String str = "" + s.charAt(1);
		return(str.equals(str.toLowerCase()));		
	}
}

Last edited by Lenny; 2010-02-26 at 05:14 AM.
Old
Profile PM WWW Search
Lenny simplifies with no grasp of the basicsLenny simplifies with no grasp of the basicsLenny simplifies with no grasp of the basicsLenny simplifies with no grasp of the basicsLenny simplifies with no grasp of the basicsLenny simplifies with no grasp of the basics
 
 
Lenny