Conversation
| public static double calculateS(double x) { | ||
| return 0d; | ||
| } | ||
| return (1 + (x * (((Math.pow(x, 2) *x) *x) / (2 * (3*2) * (4*3*2))))); |
There was a problem hiding this comment.
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; | ||
| } | ||
| } |
There was a problem hiding this comment.
It's not correct solution.
It'll loop forever for some numbers, for example, when n=27:
n>0->true-> go into while loopn%10 == 2->false-> do not dividenby10-> go to step 1.
| return false; | ||
|
|
||
| if ((a <= b && b <= c) || (a >= b && b >= c)) return true; | ||
| else return false; |
There was a problem hiding this comment.
You don't need if-else statement here as the result of your expression is boolean - so just return your expression.
| } | ||
|
|
||
|
|
||
| } |
There was a problem hiding this comment.
Please format you code before commit, you can use IDEA shortcut: CTRL+ALT+L.
| 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)))); |
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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.
| 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))))); |
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
Your factorial function doesn't return correct result.
Try to calculate on your own with n=2:
- i=1; n=2; i>=n -> true; n=n*i; i++
- i=2; n=2; i>=n -> true; n=n*i; i++
- 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"; |
There was a problem hiding this comment.
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)); |
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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.
| public static boolean isPowerOfThree(int n) { | ||
|
|
||
| if (n < 1){ | ||
| if (n <= 1){ |
There was a problem hiding this comment.
1 is 3^0 - and due to given condition you'll return false
HW_1 corrected