In this IB Computer Science lesson you will be learning about:
Java passes all primitive data types such as int, char, double and even Strings by value, however arrays and objects are a different matter. These are passed by reference.
When java passes something by reference it basically passes the memory address of the argument, so any modification made to that memory address will be reflected in the rest of the program
Here is a method that makes all the values in an array equal to zero
Before the method is called the data stored in the array is a bunch of random numbers. After the
method is called the data stored in the array is a bunch of zero’s.
There was no need to return a new array since the array b just pointed to the memory location of
the passed array values, so when you made modifications to array b, it changed the data in that
location which array a was already pointing to back in your main method.
Be careful with objects and arrays that are passed by reference, it could make your programming
easier but it may be the source of why your program is not working as expected.
1. Yearly Equivalent Interest Rate
Write a method that will convert a yearly percentage rate r compounded n times to its equivalent rate compounded once per year. Accept the yearly interest rate r and the number of compounds as arguments. Return the equivalent interest rate. Test the program by reading in 5 rates from a file. Use the formula below:
2. Even Numbers
Write a method that determines how many even numbers are in an array. Test the program with an array of 1000 random numbers between 50 and
3. Cosine Law
Write a method that accepts the 3 sides of a triangle and returns an angle. Test the program by asking the user for the 3 sides and then use the method to output all 3 sides.
4. Perfect Square
Write a method that determines if a number is a perfect square. Return true if it is and false if it is not. Test the program by using the method to find all the perfect squares less than 10000.
Check out our programing in python courses that focus on high school level coding.
These courses are complete with interactive coding lessons, teacher led videos, and more practice questions with complete solutions
Return To International Baccalaureate Computer Science Main Page