• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Determine if a character is upper case using a method

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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");
}


}
 
Ranch Hand
Posts: 75
Android Chrome Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.

 
Bartender
Posts: 825
5
Python Ruby Java
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
author
Posts: 23951
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Posts: 23951
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Can't .... do .... plaid .... So I did this tiny ad instead:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic