-2

My program has 3 Strings, that the user has already input, the purpose for this program is to capitalize all letters in the words. How do I capitalize all letters in each word using the toUpperCase(). This is what I have so far, this is a java code

public static String reverseOrder(String word1, String word2, String word3) {

if (word1.length() == 0) return word1;
    return word1.substring(0, 1).toUpperCase() + word1.substring(1).toUpperCase();
}

I have only done it for 1 word but I need to capitalize all 3 words, thanks ***ok new code is this

public static String reverseOrder(String word1, String word2, String word3) {
  int a = word1.length();
  int b = word2.length();
  int c = word3.length();

  String x;
  String y;
  String z;


  x = word1.toUpperCase();
  y = word2.toUpperCase();
  z = word3.toUpperCase();
}
}
  • You should let us know which language you're using... – jez Nov 20 '16 at 21:36
  • [`return word3.toUpperCase() + word2.toUpperCase() + word1.toUpperCase();`](http://ideone.com/1fYcVC)? – Wiktor Stribiżew Nov 20 '16 at 23:38
  • Can you show a sample input/output? – assylias Nov 20 '16 at 23:39
  • 2
    You have a function that receives three strings and returns only one. So either you need to combine the strings together, or you need to return some sort of array/collection/object to return each of them. Also you have a lot more code than you actually need to just uppercase a string... – jcaron Nov 20 '16 at 23:39

1 Answers1

0

You seem to be over complicating a problem that can be tackled in quite a simple manner. We can convert a string to upper case as follows:

String exampleString = "test";
return exampleString.toUpperCase();

In your situation, you have three strings. Why not concatenate them all together so you can convert them as one? For example:

String a = "one";
String b = "two";
String c = "three";

String combined = a + b + c;
return combined.toUpperCase();

If you're able to modify the return type there are other options, but that may fall outside the scope of the question.

BeepBeep
  • 151
  • 3
  • 9