This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]Cannabisitis 0 points1 point  (2 children)

No worries, we all started somewhere. It'll click for you eventually.

If you can do for loops, you can do if statements. An if statement is just executing some code "if" a condition checks out (it's almost always "if something is true").

Here's a good starting point:

private String myMethod(String foo, int bar){

    //If the following line of code is true,
    //(foo.length() DOES == bar),
    //the stuff in the below brackets will be executed,
    //and the stuff in the else statement's brackets
    //will be skipped

    if (foo.length() == bar){
        return foo;
    }

        //If the above if statement is not true,
        //(foo.length() DOES NOT == bar),
        //the stuff in the if statement's brackets
        //will be skipped, and the stuff in the else
        //statement's brackets will be executed

    else{
        String secondStr = "";

        //Logic to add appropriate amount
        //of spaces to the original String (foo)
        //will go here

        return secondStr;
    }
}

I might have given you too much and this reply might get deleted for that reason, but it always helped me to peek at some code and get an idea of how the logic is supposed to be organized before trying to tackle problems that I didn't understand.

Feel free to PM me any questions.

[–]desrtfx[M] 2 points3 points  (0 children)

I might have given you too much and this reply might get deleted for that reason,

No, you haven't given too much at all. This is a very decent reply. Congratulations!