-
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
Changes from 19 commits
98b24d8
e503c11
acc3464
8799a43
7f837c1
37593ef
b75ec08
8700a08
019f618
81b9696
ee4caf7
3aed8cb
2baea2a
2171f98
4abd5c1
cb12feb
479aac0
d142eb7
262edc9
716187b
6235854
b2e70d1
178929e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,7 @@ | |
|
||
public class Task1 { | ||
public static double calculateP(double a) { | ||
return 0; | ||
|
||
return 4 * a; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,7 @@ | |
|
||
public class Task2 { | ||
public static int getMeters(int centimeters) { | ||
return 0; | ||
|
||
return centimeters / 100; | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,14 @@ | |
public class Task4 { | ||
|
||
public static double getSumOfGreatest(double a, double b, double c) { | ||
return 0; | ||
} | ||
} | ||
if (a < b && b < c) { | ||
return c + b; | ||
} | ||
if (a > b && b > c) { | ||
return b + a; | ||
} | ||
else { | ||
return a + c; | ||
} | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please format you code before commit, you can use IDEA shortcut: |
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 commentThe 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 But, anyway, it do pass all the tests. |
||
} | ||
|
||
private static double calculateB(double z) { | ||
return 0; | ||
return 1 + (Math.pow(z, 2)) / (3 + ((Math.pow(z, 2)) / 5)); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,10 +2,19 @@ | |
|
||
public class Task6 { | ||
public static double calculateS(double x) { | ||
return 0d; | ||
return (1 + x + (Math.pow(x, 2)/factorial(2)) + (Math.pow(x, 3)/factorial(3)) + (Math.pow(x, 4)/factorial(4))); | ||
|
||
} | ||
|
||
private static int factorial(int n) { | ||
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 commentThe reason will be displayed to describe this comment to others. Learn more. Your factorial function doesn't return correct result.
As you see - you'll loop until you'll get overflow on int value and number will be negative. |
||
} | ||
|
||
public static double calculateZ(double x, double y) { | ||
return 0d; | ||
|
||
return Math.sin(Math.pow(x, 3)) + Math.pow(Math.cos(y), 2); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,34 @@ | |
|
||
public class Task7 { | ||
public static String getDayTitle(int dayIndex) { | ||
return ""; | ||
|
||
switch (dayIndex) | ||
{ | ||
case 1: | ||
return "Monday"; | ||
|
||
case 2: | ||
return "Tuesday"; | ||
|
||
case 3: | ||
return "Wednesday"; | ||
|
||
case 4: | ||
return "Thursday"; | ||
|
||
case 5: | ||
return "Friday"; | ||
|
||
case 6: | ||
return "Saturday"; | ||
|
||
case 7: | ||
return "Sunday"; | ||
|
||
default: | ||
return "Error"; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. you should return error in lowercase: |
||
} | ||
|
||
|
||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,10 @@ | |
|
||
public class Task8 { | ||
public static int calculateSum(int N) { | ||
return 0; | ||
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 commentThe reason will be displayed to describe this comment to others. Learn more. Check task description again. |
||
return result; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,15 @@ | |
public class Task9 { | ||
|
||
public static boolean isPowerOfThree(int n) { | ||
return false; | ||
} | ||
|
||
if (n < 1){ | ||
return false; | ||
} | ||
|
||
while (n % 3 == 0) { | ||
n = n / 3; | ||
} | ||
return true; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This implementation doesn't work. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Check again that your solution do pass all the given test cases. |
||
} | ||
} | ||
|
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.