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
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Up @@ -4,6 +4,15 @@
public class Task10 {

public static boolean containDigitTwo(int n) {

while (n > 0) {
if (n % 10 == 2) {
return true;
}
n = n / 10;

}
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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Up @@ -2,6 +2,9 @@

public class Task3 {
public static boolean isBetween(int a, int b, int c) {
return false;

return ((a <= b && b <= c) || (a >= b && b >= c));

}
}

Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
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.

}
Original file line number Diff line number Diff line change
Expand Up @@ -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.

}

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
Expand Up @@ -2,10 +2,20 @@

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) {
int result = 1;
for (int i = n; i > 0; i--) {
result = result * i;
}
return result;
}

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
Expand Up @@ -3,6 +3,33 @@

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";
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

public class Task8 {
public static int calculateSum(int N) {
return 0;
int result = 0;

for (int i = N; 2 * N >= i; i++)
result+= i*i;
return result;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,15 @@
public class Task9 {

public static boolean isPowerOfThree(int n) {
return false;
}

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

return false;
}

while (n>1 && (n % 3) == 0) {
n = n / 3;
}
return n == 1;
}
}