Subjects
PRICING
COURSES
SIGN IN
Start Free Trial
Nisha V.
Graduate Student at NYU
Tutor Satisfaction Guarantee
Java Programming
TutorMe
Question:

Write a program to implement the following loop in Java. 1 12 123 1234 12345

Nisha V.
Answer:

When it comes to loops, we need to pay attention to the pattern. In the above question, for line 1 (which translates to iteration 1) we just print 1 number, which is 1. In line/iteration 2, we print 2 numbers, but starting from 1. In the third iteration/line we print 3 numbers, starting from 1 again. Do you see a pattern? The line or the iteration decides how many numbers are to be printed. And in each iteration, we print numbers starting from 1 to the iteration-th number. (For instance, if line 3, we print numbers from 1 to 3) From this, we can see that we need 2 loops, one to find out which iteration, and the second to print the numbers. In Java (or any other programming languages) the variable that we use for loops/iterations is 'i' and subsequent iterations have the next alphabetical variables. The java pseudocode for the above program is: for(int i=1; i<=5; i++) { for(int j=1; j<=i; j++) { System.out.print(j); } System.out.println(); } We use the for loop because we know how many times the loop has to run. for loop has 3 parts: initialization, end point, incrementing/decrementing factor. In the outer loop - for (int i=i; i<=5; i++) - int i=1 is the initialization for the loop variable i - that means it starts from 1. i<=5 is the end point declaration - so this loop will run until i=5, i++ is the incrementing factor - i will increase by 1 for every iteration. Also note that we use semi colons (;) after every part in the for loop. In the inner loop, for (int j=1;j<=i;j++) means that j starts from 1 and j runs up until i, and j gets incremented by 1 every time. This would print the required solution.

Basic Math
TutorMe
Question:

It takes John 5 hours to clean 2 apartments. How long will he take to clean 10 apartments at the same rate, if he works for 10 hours per day (Answer in the number of days)?

Nisha V.
Answer:

2 and a half days. Always remember, in most of such questions, if you calculate the amount for '1' quantity, it's easy to figure the answer. For instance, in this question, John takes 5 hours to clean 2 apartments. We can either calculate how long John takes to clean 1 apartment, or how many apartments John cleans in 1 hour. However, in this question, we need to find in terms of apartments, so we will calculate how long John takes to clean 1 apartment. 5 hours - 2 apartments ? hours - 1 apartment This is a direct proportion problem, so we can use the X method, that is 5 x 1 = ? x 2 => ? = (5x1)/2 => 2.5 hours. Now that you know how long John takes to clean 1 apartment, we can calculate how long John will take to clean 10 apartments at the same rate. => 2.5 x 10 = 25 hours. The question doesn't end here. It is mentioned that he only works for 10 hours in a day. However, he takes 25 hours to clean 10 apartments. So now, we break the 25 hours into blocks of 10 to get our answer. Day 1 - 10 hours Day 2 - 10 hours Day 3 - 5 hours. So totally 2 days and 5 hours. Since he works 10 hours a day, 5 hours is half a day. That brings the solution to 2 and a half days. Which is our solution.

Set Theory
TutorMe
Question:

In a class, 32% of the students were enrolled in Math, 65% in English, and 24% in both English and Math. How many percent of students were not enrolled in English or Math?

Nisha V.
Answer:

For Answers like these, we use the Venn Diagram. It is very easy to formulate an answer that way. In this question, we do not have a number of students, but just the percentage. For simplicity and our ease. We assume that the class has 100 students. If the class has 100 students, 32 of them are enrolled in Math; 65 in English and 24 in Both Math and English. Your Venn Diagram will have a big rectangle (which is the total number of students - 100). Inside which there will be 2 overlapping circles. One circle is for English and the other for Math, and the part where they overlap would be for both English and Math. We need to find out how many students are neither in English nor in Math, which would be the area which isn't in the circle. So, the total students - (number of english students + number of Math students - number of both Math & English Students ) is what we want. 100 - (32+65-24) = 100 - 73 = 27. Since we need the answer in percentage, and we have assumed that there are totally 100%, the answer is 27%.

Send a message explaining your
needs and NISHA will reply soon.
Contact NISHA
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.