File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes Determine if a character is upper case using a method Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Determine if a character is upper case using a method" Watch "Determine if a character is upper case using a method" New topic
Author

Determine if a character is upper case using a method

Eliza Barns
Greenhorn

Joined: Dec 10, 2012
Posts: 4
Hi
I'm new to java - can anyone help?
I'm trying to determine if a character is upper case. I must use its own method which I should call in the main. Can anyone spot my obvious mistake?
Thanks


import java.util.*;

public class CharRange {

public static void main (String[] args){
Scanner keyboard = new Scanner (System.in);
System.out.println("please enter a character to test");
char input = keyboard.nextLine().charAt(0);
System.out.println("You said: " + input);
isCapital(input);
}

public static void isCapital(char example){
char example;
if('a' <= example && example >= 'z')
System.out.println ("This is a lowercase character");
else if('A' <= example && example >= 'Z')
System.out.println("This is an uppercase character");
else
System.out.println("void entry...this is a symbol");
}


}
Aj Prieto
Ranch Hand

Joined: Sep 28, 2012
Posts: 72

Do you have to write your own method?

Another option would be to use the isLowerCase method in the Character class.



Da mihi sis bubulae frustum assae, solana tuberosa in modo Gallico fricta ac quassum lactatum coagulatum crassum.
Kemal Sokolovic
Bartender

Joined: Jun 19, 2010
Posts: 825
    
    5

Welcome to the Ranch!

Please UseCodeTags (<-click) when posting your code. You'll make it easier to read for each of us trying to help you.

Your isCapital() method has invalid conditions for checking what you want. I'm not going to give you the exact code, but let's try with this. If you want to check if a number is inside [x, y] interval, you would check if the number is larger than or equal to x and smaller than or equal to y. Since you are checking if the character is inside some interval, you can apply the same logic.


The quieter you are, the more you are able to hear.
Eliza Barns
Greenhorn

Joined: Dec 10, 2012
Posts: 4
yes I must use a method, this is (unfortunately) essential to the question.
Eliza Barns
Greenhorn

Joined: Dec 10, 2012
Posts: 4
<= were around the wrong way! I'm so stupid. Thanks.

unfortunately it still does not work though, any other tips?

Thanks
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18824
    
  40

Eliza Barns wrote:Hi
I'm new to java - can anyone help?
I'm trying to determine if a character is upper case. I must use its own method which I should call in the main. Can anyone spot my obvious mistake?
Thanks



A good starting point to figure out the mistake is with the error message that the compiler spits out -- so what happens when you compiled it?

Henry


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
Eliza Barns
Greenhorn

Joined: Dec 10, 2012
Posts: 4
I know now I don't need

char example;

in isCapital. The problem now is (if I test it, for example I enter "j") it doesn't recognise this is a lower case and throws throws me the else statement!

Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18824
    
  40

Eliza Barns wrote:I know now I don't need

char example;

in isCapital. The problem now is (if I test it, for example I enter "j") it doesn't recognise this is a lower case and throws throws me the else statement!


Perhaps it would be a good idea to show us your new version of your program?

Henry
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Determine if a character is upper case using a method