-
Notifications
You must be signed in to change notification settings - Fork 13
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
base: master
Are you sure you want to change the base?
HW1_done #14
Conversation
@@ -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))))); |
There was a problem hiding this comment.
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; | ||
} | ||
} |
There was a problem hiding this comment.
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
:
n>0
->true
-> go into while loopn%10 == 2
->false
-> do not dividen
by10
-> 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.
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.
} | ||
|
||
|
||
} |
There was a problem hiding this comment.
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)))); |
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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.
@@ -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))))); |
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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:
- 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.
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)); |
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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
.
There was a problem hiding this 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){ |
There was a problem hiding this comment.
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
HW_1 corrected