Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2011-09-14
9
Medium Priority
?
265 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 2000 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
Build and deliver software with DevOps

A digital transformation requires faster time to market, shorter software development lifecycles, and the ability to adapt rapidly to changing customer demands. DevOps provides the solution.

 

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
 
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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

How to remove superseded packages in windows w60 or w61 installation media (.wim) or online system to prevent unnecessary space. w60 means Windows Vista or Windows Server 2008. w61 means Windows 7 or Windows Server 2008 R2. There are various …
Having just graduated from college and entered the workforce, I don’t find myself always using the tools and programs I grew accustomed to over the past four years. However, there is one program I continually find myself reverting back to…R.   So …
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.

721 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