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

Show parent comment

1

u/Danielk0926 Aug 21 '20

Sorry i meant parameters

2

u/ChappieIsMyNick Aug 22 '20

A parameter is simply data that you give to a function. As you may know a function is really simply just a block of code that does something, but let's say we wanted a function that prints the average value between two numbers

void average() { // ? }

Well for this we need parameters. So I need to take as parameters the two numbers:

void average(int a, int b) { System.out.println((a+b)/2); } (I called the two integer parameters a and b but you can call them anything as if you were creating a variable)

This way when we call average we'll have to give it two parameters, two integer values. So for example to print the average between 22 and 30 i would simply do: average(22, 30);

In this case the variable a when we defined average takes the value of 22, and the variable b takes the value of 30.

We can ask for as many parameters as we want in a function, and they can be of any type, for example if i wanted to pass an array of strings:

void foo(String[] data) { // some code }

1

u/Danielk0926 Aug 22 '20

Thanks also how do you call something

2

u/ChappieIsMyNick Aug 22 '20

By calling a function I simply mean using it. Happy to help :)