-1

I need "args[i]" to be converted to Uppercase so the output will be:

"$ARG1" line break
"$ARG2" line break
"$ARG3" line break

and so on. I need to use the "toUpperCase" method but don't know how.

public class Main {
    public static void main(String[] args) {
        System.out.println("Number of args:" +
           args.length);
        for(int i=0; i<args.length; i++){
            char dollar = '\u0024';
            System.out.println(dollar + args[i]);
        }
    }
}
azurefrog
  • 10,785
  • 7
  • 42
  • 56
Marie Mirbekian
  • 183
  • 1
  • 2
  • 9
  • What do you mean when you say you "don't know how" to call `toUpperCase()`? You don't know how to call a method on an object? – azurefrog Jun 22 '15 at 20:34
  • You know that whether or not it will print ARG1 or something else depends on what you pass to the program as command line arguments. If you run your program as `java Main a b c` then you'll get `$A $B $C` (with line breaks). Also, isn't it simpler to use `'$'` rather than `'\u0024'`? – RealSkeptic Jun 22 '15 at 20:37
  • yes dear ..exactly:) – Marie Mirbekian Jun 22 '15 at 20:37
  • RealSkeptic got iit ! haha actually I needed to have some practice with unicodes.. I'm a beginner :D..thx – Marie Mirbekian Jun 22 '15 at 20:40
  • See related answers http://stackoverflow.com/questions/10320200/turn-a-user-input-string-to-upper-case-java and http://stackoverflow.com/questions/5365728/java-how-do-you-convert-lower-case-string-values-to-upper-case-ones-in-a-string – Blake Yarbrough Jun 22 '15 at 20:47
  • very cool ! I'll check it out! – Marie Mirbekian Jun 22 '15 at 20:48
  • Why does this have 7 upvotes – Tim Jun 22 '15 at 21:21

4 Answers4

5

Java has this functionality built into the String object like so:

 System.out.println(dollar + args[i].toUpperCase());

See the Oracle documentation here

Blake Yarbrough
  • 2,286
  • 1
  • 20
  • 36
4

Just use .toUpperCase() on any String, and it will return an all-upper-case String.

System.out.println(dollar + args[i].toUpperCase());
Tim
  • 41,901
  • 18
  • 127
  • 145
3

java has String method :public String toUpperCase()

public class Main {
    public static void main(String[] args) {
        System.out.println("Number of args:" + args.length);

        for(int i=0; i<args.length; i++){
            char dollar = '\u0024';
            System.out.println(dollar + args[i].toUpperCase());
        }

    } 
}

See the Oracle documentation here

Blake Yarbrough
  • 2,286
  • 1
  • 20
  • 36
1
public class Main {
    public static void main(String[] args) {
        System.out.println("Number of args:" +
           args.length);
        char dollar = '\u0024';
        for(int i=0; i<args.length; i++){
            System.out.println(dollar + args[i].toUpperCase());
        }
    }
}
user2473015
  • 1,392
  • 3
  • 22
  • 47