469,934 Members | 1,824 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,934 developers. It's quick & easy.

ChangeCase.java

Im trying to create a script that reverses the case of all characters of an argument from the command line:

This is what i got:
Expand|Select|Wrap|Line Numbers
  1. public class ChangeCase {
  2.  
  3.   public static void main (String args[])  {
  4.  
  5.         String tempString;
  6.         char tempCharacter;
  7.         char tempCharUp;
  8.         char tempCharDown;
  9.  
  10.         for (int i=0 ; i < args.length ; i++){
  11.         tempString = args[i];
  12.         tempCharacter = tempString.charAt(i);
  13.         tempCharUp = tempCharacter.toUpperCase();
  14.         tempCharDown = tempCharacter.toLowerCase();
  15.                 if (tempCharacter.equals(tempCharUp)){
  16.                         tempCharacter = tempCharDown;
  17.                         System.out.println (tempCharacter);
  18. }
  19.                 else {
  20.                         tempCharacter = tempCharUp;
  21.                         System.out.println (tempCharacter);
  22.                      }
  23.                 }
  24.          }
  25. }
  26.  
But im getting this:
ChangeCase.java:15: char cannot be dereferenced
tempCharUp = tempCharacter.toUpperCase();
^
ChangeCase.java:16: char cannot be dereferenced
tempCharDown = tempCharacter.toLowerCase();
^
ChangeCase.java:17: char cannot be dereferenced
if (tempCharacter.equals(tempCharUp)){
^
3 errors

Any sugestions please, im quite new to java.

Regards in advance.
Apr 23 '07 #1
7 2605
sandyw
122 100+
Question what does char mean to you.

sandyw
Apr 23 '07 #2
Character?
Apr 23 '07 #3
sandyw
122 100+
You might be using char for the wrong reason.
Review what char mean...

or I might be wrong...
sandyw
Apr 23 '07 #4
JosAH
11,448 Expert 8TB
A char is a primitive and it hasn't any methods; that's what your compiler is
whining about. Have a look at the Character class and its many utility
methods. Hint: pay special attention to the methods isLowerCase, isUpperCase,
toLowerCase and toUppercase.

kind regards,

Jos
Apr 24 '07 #5
r035198x
13,262 8TB
Im trying to create a script that reverses the case of all characters of an argument from the command line:

This is what i got:
Expand|Select|Wrap|Line Numbers
  1. public class ChangeCase {
  2.  
  3. public static void main (String args[]) {
  4.  
  5. String tempString;
  6. char tempCharacter;
  7. char tempCharUp;
  8. char tempCharDown;
  9.  
  10. for (int i=0 ; i < args.length ; i++){
  11. tempString = args[i];
  12. tempCharacter = tempString.charAt(i);
  13. tempCharUp = tempCharacter.toUpperCase();
  14. tempCharDown = tempCharacter.toLowerCase();
  15. if (tempCharacter.equals(tempCharUp)){
  16. tempCharacter = tempCharDown;
  17. System.out.println (tempCharacter);
  18. }
  19. else {
  20. tempCharacter = tempCharUp;
  21. System.out.println (tempCharacter);
  22. }
  23. }
  24. }
  25. }
  26.  
But im getting this:
ChangeCase.java:15: char cannot be dereferenced
tempCharUp = tempCharacter.toUpperCase();
^
ChangeCase.java:16: char cannot be dereferenced
tempCharDown = tempCharacter.toLowerCase();
^
ChangeCase.java:17: char cannot be dereferenced
if (tempCharacter.equals(tempCharUp)){
^
3 errors

Any sugestions please, im quite new to java.

Regards in advance.
tempCharacter.toUpperCase(); is not allowed. Look at API specs for the Character class to see how to convert characters.
Apr 24 '07 #6
r035198x
13,262 8TB
A char is a primitive and it hasn't any methods; that's what your compiler is
whining about. Have a look at the Character class and its many utility
methods. Hint: pay special attention to the methods isLowerCase, isUpperCase,
toLowerCase and toUppercase.

kind regards,

Jos
Hey I thought my connection was faster than Jos' connection ...
Apr 24 '07 #7
JosAH
11,448 Expert 8TB
Hey I thought my connection was faster than Jos' connection ...
I already had my espresso so I'm amazingly fast this morning ;-)

kind regards,

Jos
Apr 24 '07 #8

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

2 posts views Thread by Michael | last post: by
reply views Thread by Ravi Tallury | last post: by
1 post views Thread by ptaz | last post: by
reply views Thread by Markus Wollny | last post: by
oll3i
reply views Thread by oll3i | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.