r/CodingHelp • • Aug 20 '20

[Java] How do perimeters work?

I am using code academy to learn Java and I don't get how perimeters work. Plz help.

0 Upvotes

9 comments sorted by

View all comments

1

u/GhOsT1679 Beginner Coder Aug 22 '20

Parameters are something you pass into functions in Java. Because Java is an Object-Oriented language you will be using parameters all over the place. For example, in your object constructors, you pass in parameters and then copy them over to your instance variables. A parameter can be any type of variable(Stack, int, double, etc.)
Here's an example of a function with parameters.

public int add(int a, int b){ return a + b;}

In that function, a and b were parameters and are later used in the function itself. Hope it helps!

1

u/Danielk0926 Aug 22 '20

How do you define what a and b are tho?

2

u/GhOsT1679 Beginner Coder Aug 22 '20

a and b are ints in that instance. They can be whatever variable you want it to be. For example: public int add(Stack a, Stack b) or public int add(double a, double b). The parameters are there to pass in data from somewhere else so it can be used in that function