TutorMe homepage

SIGN IN

Start Free Trial

Albert P.

Software engineer and experienced tutor

Tutor Satisfaction Guarantee

Java Programming

TutorMe

Question:

Find the sum of the integers that are divisible by 2 up to 100.

Albert P.

Answer:

We can check if a number is divisible by two by checking if its remainder is equal to zero. In Java programming we can either use the division or mod operator. The portion of Java code that can check if a number is divisible by two can be seen below: int x = 50; if (x % 2 == 0) { // x is divisible by 2 } The modulus operator evaluates the remainder in numeric division. If the result of the modulus operator equals 0 then we know that the number (in this case 'x' is divisible by 2). Next, we need to iterate from 1 to 100 and sum up the values that are divisible by 2. First we will focus on iterating from 1 to a 100. We can use a for loop to accomplish this. A for loop will iterate from a beginning and ending index. We can use our conditional statement above inside of our for loop to determine if a number is divisible by 2. for (int x = 1; x <= 100; x++) { if (x % 2 == 0) { // x is divisible by 2 } } Next, we will need to sum up the values that are divisible by 2. int sum = 0; for (int x = 1; x <= 100; x++) { if (x % 2 == 0) { sum += x; } } The sum += x expression will take the sum and add it to x. It is the equivalent of sum = sum + x. Lastly, we will need to put our code within a Java class. The code can be seen below. public class SumDivisibleByTwo { public static void main(String[] args) { int sum = 0; for (int x = 1; x <= 100; x++) { if (x % 2 == 0) { sum += x; } } System.out.println("The sum of numbers divisible by 2 up to a 100 is: " + sum); } } We will need to paste the above code within a .Java with a name of SumDivisibleByTwo. The final name should look like SumDivisibleByTwo.java. Run the program by running the following commands. javac SumDivisibleByTwo.java java SumDivisibleByTwo We can see the following output: The sum of numbers divisible by 2 up to a 100 is: 2550

Calculus

TutorMe

Question:

Find the derivative of f(x) = x^2.

Albert P.

Answer:

The derivative for exponents can be found by applying the below equation to f(x). lim h -> 0 f(a + h) - f(a) / h By applying the above formula (substituting 'a + h' and 'a' into the equation) we get the following. lim h -> 0 (a + h)^2 - a^2 / h = lim h -> 0 ((a^2 + 2ah + h^2) - a^2) / h = lim h -> 0 (2ah + h2) / h From here we can factor out an h. lim h -> 0 h(2a + h) / h = lim h -> 0 (2a + h) In the equation above, as h goes zero we will get 2a. lim h -> 0 (2a + h) = 2a Thus, the derivative of f(x) = x^2 is equal to 2x. f'(x) = 2x

Statistics

TutorMe

Question:

Adam flips a coin three times. What is the probability that he gets at least two heads (order does not matter)?

Albert P.

Answer:

We will mark each flip condition with an 'H' to represent heads and a 'T' to represent tails. If Adam flips the coin three times he will have different possible outcomes each time. He could receive the following results. HHH HHT HTH THH TTT TTH THT HTT By looking at the results, we can see that Adam can get heads by HHH, HHT, HTH or THH. The probability of getting a heads is 0.5. Similarly, the probability of getting a tails is 0.5. Thus, the probability of getting HHH is equal to 0.5 X 0.5 X 0.5. The probability of getting HHT is equal to 0.5 X 0.5 X 0.5. The probability of getting HTH is equal to 0.5 X 0.5 X 0.5. Lastly, the probability of getting HHH is equal to 0.5 X 0.5 X 0.5. HHH = (0.5)(0.5)(0.5) = 0.125 HHT = (0.5)(0.5)(0.5) = 0.125 HTH = (0,5)(0,5)(0.5) = 0.125 THH = (0.5)(0.5)(0.5) = 0.125 In all these cases (HHH, HHT, HTH and THH) we receive two heads. Thus, we must sum all these outcomes and get our probability. P(atleast 2 heads) = 0.125 + 0.125 + 0.125 + 0.125 = 0.5

Send a message explaining your

needs and Albert will reply soon.

needs and Albert will reply soon.

Contact Albert

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

© 2019 TutorMe.com, Inc.