Enable contrast version

Tutor profile: Aaron C.

Inactive
Aaron C.
Computer Science Researcher and University Student
Tutor Satisfaction Guarantee

Questions

Subject: Python Programming

TutorMe
Question:

Write a function to take the average of a list of numbers.

Inactive
Aaron C.
Answer:

def average(list): sum = 0 for num in list: sum += num return sum / len(list)

Subject: Java Programming

TutorMe
Question:

Why does the following code not behave as intended: String s1 = new String("hello"); String s2 = "hello"; if(s1 == s2){ System.out.println("Both strings are equal!"); }else{ System.out.println("The strings are not equal!"); }

Inactive
Aaron C.
Answer:

The problem with the above code is that it uses == to compare two strings. The == operator compares based on reference (whether or not they are the same object). However, we want to compare the actual contents of s1 and s2. Thus, the if statement should be changed to the following to utilize the .equals method of the String class: if(s1.equals(s2)){ ...

Subject: C Programming

TutorMe
Question:

What is the problem with the following code: #include <stdio.h> #include <stdlib.h> int main(int argc, int argv) { int* array; int i; array = malloc(10 * sizeof(int)); for(i = 0; i < 10; ++i){ array[i] = i; } return 0; }

Inactive
Aaron C.
Answer:

The code provided has a memory leak, malloc is called but the memory is never freed. Prior to returning 0, there should be the following line: free(array);

Contact tutor

Send a message explaining your
needs and Aaron will reply soon.
Contact Aaron

Request lesson

Ready now? Request a lesson.
Start Lesson

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 Lesson" 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.