TutorMe homepage

SIGN IN

Start Free Trial

Daanish M.

Student Tutor Who Can Help K-12 Students

Tutor Satisfaction Guarantee

Java Programming

TutorMe

Question:

How do you copy an Array in Java?

Daanish M.

Answer:

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]

Pre-Algebra

TutorMe

Question:

Solve: x^2-4 = 77

Daanish M.

Answer:

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

Basic Math

TutorMe

Question:

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

Daanish M.

Answer:

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.

Send a message explaining your

needs and Daanish will reply soon.

needs and Daanish will reply soon.

Contact Daanish

Ready now? Request a lesson.

Start Session

FAQs

What is a lesson?

A lesson is virtual lesson space on our platform where you and a tutor can communicate.
You'll have the option to communicate using video/audio as well as text chat.
You can also upload documents, edit papers in real time and use our cutting-edge virtual whiteboard.

How do I begin a lesson?

If the tutor is currently online, you can click the "Start Session" button above.
If they are offline, you can always send them a message to schedule a lesson.

Who are TutorMe tutors?

Many of our tutors are current college students or recent graduates of top-tier universities
like MIT, Harvard and USC.
TutorMe has thousands of top-quality tutors available to work with you.

Made in California

© 2018 TutorMe.com, Inc.