Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Java

00PS. Forgot how to make a parameter!

String, int, what?

1 Answer

You question is pretty broad, but to create a simple String and int variable you would do:

String stringVariable = "blah";
int intVariable = 5;

Make sure you add the semi-colon at the end of the variable.

Sorry, wrote my question wrong though.

Sorry it's taken me so long to respond, I often get very busy with other coding projects and forget to check the forums for replies.

If you're looking on how to add a parameter to your method, I can show you a quick example.

ArgumentExamples.java

public class ArgumentExamples {
    public static void main(String[] args) {
        String strArgument = "Testing123";
        int intArgument = 12;
        Test(strArgument);
        Test2(intArgument);

        //while invoking these 2 methods instead of creating the 2 vars, I could've just passed a String and int value directly like so:
        //Test("You don't technically need a String variable");
        //Test2(100);
    }

    public static void Test(String parameter) {
        System.out.println(parameter);
    }

    public static void Test2(int parameter) {
        System.out.println(parameter);
    }
}

OUTPUT

Testing123
12

In this example, my Test() method takes a String parameter, and then prints it out to the screen, and my second method Test2() takes an int as a parameter and prints it out to the screen. The arguments that I am passing into these 2 methods are the variables "strArgument" and "intArgument".

I hope this helps you out, if you're still confused I can try to re-explain a different way.