• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Determine if a character is upper case using a method

 
Eliza Barns
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 75
Android Chrome Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Do you have to write your own method?

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

 
Kemal Sokolovic
Bartender
Posts: 825
5
Java Python Ruby
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Eliza Barns
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
yes I must use a method, this is (unfortunately) essential to the question.
 
Eliza Barns
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
<= were around the wrong way! I'm so stupid. Thanks.

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

Thanks
 
Henry Wong
author
Marshal
Pie
Posts: 21022
78
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Eliza Barns
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Marshal
Pie
Posts: 21022
78
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic