views:

83

answers:

5

So this is what I have so far for my vertical string.

public static void main(String[] args) {
    (**What do I put in here?**)
}

public static void vertical(String str) {
    String vertical = "hey now";
    for (int i = 0; i < str.length(); i++) {
        System.out.println(str.charAt(i));
    }
}   

My teacher checked out the "outline" part of my string. What my question here is what do I put under public static void main(String[] args) (note the parentheses) and make it produce:

h
e
y

n
o
w

I'm getting the feeling that I need to put a System.out.println there but I'm just not sure. Any help with producing the above would be greatly appreciated. Thank you very much.

Yes by using vertical (string str) I want to make hey now go vertically down. If I could get the grade just by using /n I would T-T.

+5  A: 

Your vertical method needs to be invoked. Since it is a static method, and main is also static, you can invoke it directly.

If the user is going to be supplying the word as an argument to the command line, you'd want to do:

vertical(args[0]);

You probably also want to do some checking to make sure arguments are supplied.

Michael Shimmins
+1  A: 

you call the method vertical with a string.

hvgotcodes
A: 

To build upon Michael Shimmins answer, you could also iterate across the String array, args, sending each element to the vertical method. This would allow your teacher to input multiple String inputs and see each printed.

It would look something like this (in main):

 for (String arg: args) {
    vertical(arg);
 }

To test it, run something like this:

java <your class file> "hey there" "hi there" "ho there"
bedwyr
+1  A: 

You simply call vertical. EDIT: Turns out your inputted string does matter

But, you don't need to assign String vertical = blah because you never use vertical

nearlymonolith
Look at it one more time ;) He's assigning to `vertical` but never uses it again!
Joe
Oh haha guess I didn't read it carefully enough because that just makes complete lack of sense
nearlymonolith
+1  A: 

You have to realize that you need to invoke the method. It will not simply be called by itself. Also, you need to assign str to vertical or give str a value probably the later.

Final Code:

public static void main(String[] args) {
     vertical("Hey now");
}

public static void vertical(String str) {
    //String vertical = "hey now";
    for (int i = 0; i < str.length(); i++) {
        System.out.println(str.charAt(i));
    }
}

Also, your teacher has made a mistake since, you need to do more than just change the parenthesis to actually make this work.

thyrgle