We're a community of 1076K IT Pros here for help, advice, solutions, professional growth and fun. Join us!
1,075,687 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Start New Discussion Reply to this Discussion

Converting lowercase to uppercase

Hey everyone,

I'm new at this.. so please bear with me.

Anyway, I'm really confused.

I'm supposed to convert the first character of the String firstName to upper case.

Problem is... I have no idea how to :-/

I've done so much research and reading and still nothing.

Please help me.

Thanks in advance!

This is my code;

public class Main {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {

        char firstSymbol;


        // First and Last Name

        String firstName="mickey";
        String lastName="mouse";
        System.out.println(lastName + "," + firstName);
4
Contributors
6
Replies
1 Year
Discussion Span
3 Years Ago
Last Updated
9
Views
Question
Answered
ineedhelp09
Newbie Poster
3 posts since Feb 2008
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0

Check out the java API: http://java.sun.com/j2se/1.4.2/docs/api/java/lang/Character.html

If you still can't figure it out let me know.

WhYuLoOkIn
Junior Poster in Training
55 posts since Jan 2007
Reputation Points: 10
Solved Threads: 3
Skill Endorsements: 0

Thank you for your reply.
I figured out how to do it using the replace method. However, now I'm asked to do it using the variable firstSymbol.

ineedhelp09
Newbie Poster
3 posts since Feb 2008
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0

Well if you use the replace method you will have to hard code your code. Which is ok if you know what the string variable contains, In a case where you don't know, this will not be good. So It is probably good if you get familiar with the toUpperCase method in the Character class.

Here is an example how to use it:

String unknown = " java";

//charAt gets the first character in string and upperCase converts it to uppercase	
//then I add the uppercase J to the rest of the String with substring starting at the second
//character in the string java, so basically:  J + ava -> Java	

unknown = Character.toUpperCase(unknown.charAt(0)) + unknown.substring(1);
WhYuLoOkIn
Junior Poster in Training
55 posts since Jan 2007
Reputation Points: 10
Solved Threads: 3
Skill Endorsements: 0

Thank you! Works great, But does it incorporate the firstSymbol variable I told you about? =/

ineedhelp09
Newbie Poster
3 posts since Feb 2008
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0
Question Answered as of 5 Years Ago by WhYuLoOkIn

Have you heard of unicode? In unicode each character has a corresponding number. A-Z corresponds with 65-90, while a-z corresponds with 97-122. In order to make the letter j into a capitol J you would convert the j into unicode, subtract 22, and convert back to letters, but I don't remember how to do it and I forgot to write it down in my notes LOL so just search around for unicode and it should help you.

PS I am a student and I just learned about this last week so if I'm wrong please feel free to correct me... I am trying to solve my own problems and thought I'd look around and see what else was here lol

edchabz
Newbie Poster
7 posts since Feb 2008
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0

Hi guys, converting uppercase or lowercase strings in java is so simple but if you wanna see a more complex application you can look at here...

There is a function that makes first letters of words, sentences or lines Uppercased in JAVA.
<URL SNIPPED>Uppercasing First Letters

This may be useful for learning more string operations.

webmstr
Newbie Poster
2 posts since Nov 2009
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0

This question has already been solved: Start a new discussion instead

Post: Markdown Syntax: Formatting Help
 
You
 
© 2013 DaniWeb® LLC
Page rendered in 0.1008 seconds using 2.82MB