Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HW1_done #14

Open
wants to merge 23 commits into
base: master
Choose a base branch
from
Open

HW1_done #14

wants to merge 23 commits into from

Conversation

OlgaBerezhna
Copy link

@OlgaBerezhna OlgaBerezhna commented Nov 27, 2016

HW_1 corrected

@@ -2,10 +2,13 @@

public class Task6 {
public static double calculateS(double x) {
return 0d;
}
return (1 + (x * (((Math.pow(x, 2) *x) *x) / (2 * (3*2) * (4*3*2)))));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not correct solution.
Try to solve it step-by-step.
Also you can take look at other students solutions.

if (n / 10 == 10) {
return true;
}
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not correct solution.
It'll loop forever for some numbers, for example, when n=27:

  1. n>0 -> true -> go into while loop
  2. n%10 == 2 -> false -> do not divide n by 10 -> go to step 1.

return false;

if ((a <= b && b <= c) || (a >= b && b >= c)) return true;
else return false;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You don't need if-else statement here as the result of your expression is boolean - so just return your expression.

}


}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please format you code before commit, you can use IDEA shortcut: CTRL+ALT+L.

@@ -3,10 +3,10 @@

public class Task5 {
public static double calculateA(double x, double y, double z) {
return 0;
return ((2 * Math.sin(x - Math.PI / 6) * calculateB(z)) / (1 / 2.0 + (Math.pow(Math.sin(y), 2))));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's quite hard to read such expressions. It'll be easier for understanding if you'll split it into some pretty parts, like top-part of expression, bottom-part of expression.

But, anyway, it do pass all the tests.

dayNumber = "Error";
break;
}
return dayNumber;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's no need for dayNumber variable here. Just do return in each case clause.
Also, you should return Error in lowercase to pass the test.

while (n % 3 == 0) {
boolean b = (n / 3) == 3;
}
return true;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This implementation doesn't work.
You need to re-assign value of n/3 back to n, cause right now you'll have infinite loop in many cases.

@xSAVIKx xSAVIKx self-assigned this Nov 27, 2016
@@ -2,10 +2,16 @@

public class Task6 {
public static double calculateS(double x) {
return (1 + (x * (((Math.pow(x, 2) *x) *x) / (2 * (3*2) * (4*3*2)))));
return (1 + (x * (((Math.pow(x, 2) *x) *x) / (factorial(2)*factorial(3)*factorial(4)))));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Your task is to calculate: 1 + x + x^2/2! + x^3/3! + x^4/4!
And you are trying to calculate: 1 + (x * x^2 * x * x) / (2! * 3! * 4!)

for (int i = 1; i <= n; i++) {
n = n * i;
}
return n;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Your factorial function doesn't return correct result.
Try to calculate on your own with n=2:

  1. i=1; n=2; i>=n -> true; n=n*i; i++
  2. i=2; n=2; i>=n -> true; n=n*i; i++
  3. i=3; n=4; i>=n -> true; n=.....

As you see - you'll loop until you'll get overflow on int value and number will be negative.

return "Sunday";

default:
return "Error";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you should return error in lowercase: "error"

int result = 0;
int i;
for (i = N; 2 * N >= i; i++)
result = (int) (i + Math.pow((2 * N), 2));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Check task description again.
You should calculate: N^2 + (N+1)^2 + (N+2)^2+ ... + (N+N)^2

while (n % 3 == 0) {
n = n / 3;
}
return true;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Check again that your solution do pass all the given test cases.
For example, if n=15 you'll return true, while 15 is not power of 3.

Copy link
Member

@xSAVIKx xSAVIKx left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please fix error with 3^0.

@@ -4,14 +4,14 @@

public static boolean isPowerOfThree(int n) {

if (n < 1){
if (n <= 1){
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1 is 3^0 - and due to given condition you'll return false

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants