# Tutor profile: Daanish M.

## Questions

### Subject: Java Programming

How do you copy an Array in Java?

How NOT to copy an Array in Java Arrays in Java are Objects. If you try to treat them as variables… well you can(!) but what you are really copying is the reference!. The example below explains this statement. import java.util.Arrays; public class HowNOTtoCopyAnArray { public static void main(String[] args){ int[] x = {1, 2, 3, 4, 5}; int[] y = x; //don't copy array like this! System.out.println(Arrays.toString(x)); System.out.println(Arrays.toString(y)+"\n"); x[1] = 22; // y[1] will display 22! same reference System.out.println(Arrays.toString(x)); System.out.println(Arrays.toString(y)+"\n"); y[4] = 55; // x[4] will display 55! System.out.println(Arrays.toString(x)); System.out.println(Arrays.toString(y)); } } Instead, Use Object.clone(): Arrays inherit methods from Object class, and clone is one of them. If you need to copy an Array as it is then this is the method you should use. import java.util.Arrays; public class CloneArray { public static void main(String[] args){ int[] x = {1, 2, 3, 4, 5}; int[] y = x.clone(); System.out.println(Arrays.toString(x)); System.out.println(Arrays.toString(y)+"\n"); x[1] = 22; System.out.println(Arrays.toString(x)); System.out.println(Arrays.toString(y)+"\n"); y[4] = 55; System.out.println(Arrays.toString(x)); System.out.println(Arrays.toString(y)); } } Output: [1, 2, 3, 4, 5] [1, 2, 3, 4, 5] [1, 22, 3, 4, 5] [1, 2, 3, 4, 5] [1, 22, 3, 4, 5] [1, 2, 3, 4, 55]

### Subject: Pre-Algebra

Solve: x^2-4 = 77

1.Our goal is to get x by itself on the left hand side of the equation. We must get rid of the -4 (first) then the exponent 2. x^2-4 = 77 2. Add 4 to both sides of the equation x^2 -4 +4 = 77 +4 3. Take the Sqaure Root of both Sides (Remeber to use the +- sign) √x^2 = ±√81 4. There are 2 solutions. X is equal to Positive 9 and negative 9. x = ±9

### Subject: Basic Math

Solve for y in the following single variable equation: 3(2y + 5) = 3

1. Outline the Steps in Algebra. This is outlined in the acronym Bedmas which stands Brackets, Exponents, Division, Multiplication, Addition, Subtraction. 2. Solve For the Brackets in the equation: 3(2y+5) =3 There is nothing to solve in the brackets as there are no common terms. 3. Divide 3 from (2y+5) There are no Exponents in the equation, so we solve for division as it is next in BEDMAS. 3(2y+5) = 3 We divide 3 from (2y +5). What we do to one side we must do to the other side of the equal sign, so we dive 3 from 3 as well. Thus, the is should look like this, (3(2y+5)) /3 = 3/3 Simplified this is (2y+5) = 1 4. Now Subtract 5 from both sides to isolate the variable 2y+5-5 = 1-5 Again we do it on both sides because what we do to one side we must do to another. Simplified this looks like 2y = -4 5. The final step is to isolate for y alone. We can see that y is currently being multiplied in 2, in the form 2y. So we divide by 2 into both sides. Thus, y = (-2) The solution for y in this equation is -2.

## Contact tutor

needs and Daanish will reply soon.