Solved

How do you convert a string from toLowerCase to toUpperCase and toLowerCase to toUpperCase?

Posted on 2011-09-14
9
255 Views
Last Modified: 2012-08-14
I have no clue how to figure this problem out.

public class Strings
{
    // instance variables - replace the example below with your own
   

    /**
     * Constructor for objects of class Strings
     */
    public Strings()
    {
       
    }

    /**
     * Write a method that takes a string and returns a new string that changes the case of every character in
     * the original string changed from lowercase to uppercase and vice versa. Note that upper/lower case doesn't
     * apply to some characters such as numbers or punctuation.
     * @param  y   a sample parameter for a method
     * @return     the sum of x and y
     */
    public String changeCase(String s)
    {
        if(s.toLowerCase())
        {
            return s.toUpperCase();
            else if(s.toUpperCase())
            return s.toLowerCase();
        }
       
    }
}
0
Comment
Question by:ryanbecker24
  • 5
  • 4
9 Comments
 
LVL 47

Expert Comment

by:for_yan
ID: 36540172
Is this an academic assignemnt?
0
 
LVL 47

Accepted Solution

by:
for_yan earned 500 total points
ID: 36540175

well in any case I'm not writng anything for you but if you go to internet, you can find such things, like in this link:
http://stackoverflow.com/questions/1729778/how-can-i-invert-the-case-of-a-string-in-java
0
 

Author Comment

by:ryanbecker24
ID: 36540176
No, I have always wondered how to figure this out. I just decided to make an empty class just for fun. I know how to go from a regular string to lower case and reg string to upper case but I don't know how to go back and forth.
0
 

Author Comment

by:ryanbecker24
ID: 36540211
Thank you, I have been looking all over the internet for this. I copied and pasted it. It compiles but it doesn't show the case switch from uppercase to lowercase. It shows lowercase to uppercase. I am using BlueJ. Do you know why this is?
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 47

Expert Comment

by:for_yan
ID: 36540229
Post your exact code, I'll look at it.
0
 

Author Comment

by:ryanbecker24
ID: 36540252
public String caseChange(String s)
   {     char[] characters = s.toCharArray();    
       for (int index = 0; index < characters.length; index++)    
       {         char c = characters[index];        
           if (Character.isUpperCase(c))        
           {            
               characters[index] = Character.toLowerCase(c);        
            }         else if (Character.isLowerCase(c))        
            {             characters[index] = Character.toUpperCase(c);        
            }    
        }     return new String(characters);
    }
0
 
LVL 47

Expert Comment

by:for_yan
ID: 36540261
Just pasted your code - seesm to be working fine for me - look at the output below

 public static String caseChange(String s)
   {     char[] characters = s.toCharArray();
       for (int index = 0; index < characters.length; index++)
       {         char c = characters[index];
           if (Character.isUpperCase(c))
           {
               characters[index] = Character.toLowerCase(c);
            }         else if (Character.isLowerCase(c))
            {             characters[index] = Character.toUpperCase(c);
            }
        }     return new String(characters);
    }


    

    public static void main(String[] args) {


      System.out.println(caseChange("ASADhjRTklui54"));


}

Open in new window



output:

asadHJrtKLUI54

Open in new window

0
 

Author Comment

by:ryanbecker24
ID: 36540279
It works now. I just closed BlueJ and opened it again. Thanks.
0
 
LVL 47

Expert Comment

by:for_yan
ID: 36540284
You are welcome.

Better go away from BlueJ - that's not the most popular stuff - and perhpas has some quirks.
Rather use some normal IDE, like Eclipse.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
object oriented programming comparison 5 55
Windows 10 IE Certificate Issue 10 42
expectj telnet failing 5 26
Configure a Bean in an XML file 4 12
There is an easy way, in .NET, to centralize the treatment of all unexpected errors. First of all, instead of launching the application directly in a Form, you need first to write a Sub called Main, in a module. Then, set the Startup Object to th…
Whether you’re a college noob or a soon-to-be pro, these tips are sure to help you in your journey to becoming a programming ninja and stand out from the crowd.
The goal of this video is to provide viewers with basic examples to understand and use conditional statements in the C programming language.
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

920 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now