class Passer { void toUpperCase(String[] text) { for (int i = 0; i < text.length; i++) { text[i] = text[i].toUpperCase(); } } public static void main(String[] arguments) { Passer passer = new Passer(); passer.toUpperCase(arguments); for (int i = 0; i < arguments.length; i++) { System.out.print(arguments[i] + " "); } System.out.println(); } }
Can someone explain this code to me? I'm not quite sure I understand. This is what I'm thinknig...
From what I can understand here the toUpperCase method takes a string of text, and converts it into an array. It then loops through the entire array, turning each letter into an uppercase using this. text[i] = text[i].toUpperCase();
In the second method, called main, a string from the command-line arguments is taken and put into an array. an object called passer is created that references the upperCase method. and then from here I'm not exactly quite sure what is going on.
I see that the for loop in the main method is looping through the length of the argument string, turning each into an uppercase, but I'm not exactly sure why it works.
The void in the first method is confusing me. doesn't void mean that nothing gets returned? If nothing is getting returned, how is the main method able to get the capitalized letters from the toUpperCase method?