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

homework1 #10

Open
wants to merge 1 commit 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 @@ -3,7 +3,19 @@

public class Task10 {

public static boolean containDigitTwo(int n) {
return false;
}
public static boolean containDigitTwo(int a) {
boolean flag = false;
int aLast;
if(a == 0)
Copy link

Choose a reason for hiding this comment

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

No need in this verification and assignment because your flag is already set to false.

flag = false;
while((a/10) > 0){
Copy link

Choose a reason for hiding this comment

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

It can be just a > 0. And there will be no need in additional (a == 2) verification.

aLast = a%10;
a = a/10;
if((aLast == 2)|(a == 2)) {
Copy link

Choose a reason for hiding this comment

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

It's better to use || operator.

flag = true;
break;
}
}
return flag;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@

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;
if (((b >= a)&(b <= c))|((b >= c)&(b <= a)))
Copy link

Choose a reason for hiding this comment

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

  1. Too many ().
  2. It's better to use && and || for current verifications. Please read about difference between || and |.
  3. Can be just return ((b >= a)&(b <= c))|((b >= c)&(b <= a)); because result is boolean type.

return true;
else return false;

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,15 @@
public class Task4 {

public static double getSumOfGreatest(double a, double b, double c) {
return 0;
double x1;
double x2;
if (a >=b){
Copy link

Choose a reason for hiding this comment

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

Please use Math.max() for these purpose.

x1 = a;
} else x1 = b;
if (b >= c){
x2 = b;
} else x2 = c;

return x1 + x2;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,14 @@

public class Task5 {
public static double calculateA(double x, double y, double z) {
return 0;
double b = 1 + (Math.pow(z,2)/(3 + (Math.pow(z,2)/5)));
Copy link

Choose a reason for hiding this comment

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

Can be just double b = calculateB(z);

double up = (2*Math.sin(x-(Math.PI)/6)*b);
double down = 0.5 + Math.sin(y)*Math.sin(y);
return up / down;
}

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
@@ -1,11 +1,22 @@
package school.lemon.changerequest.java.introduction.hw1;

public class Task6 {
public static double calculateS(double x) {
return 0d;

public int factorial(int n){
Copy link

Choose a reason for hiding this comment

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

Please change it to public static int factorial(int n)

int result;
if (n==1) return 1;
result = factorial(n-1)*n;
return result;
}

public double calculateS(double x) {
Copy link

Choose a reason for hiding this comment

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

The same, please add static modifier.

double answ = 1;
for(int i=1; i<5; i++)
answ = answ + (Math.pow(x, i) / factorial(i));
return answ;
}

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,23 @@

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
@@ -1,7 +1,12 @@
package school.lemon.changerequest.java.introduction.hw1;

public class Task8 {
public static int calculateSum(int N) {
return 0;
public static double calculateSum(double N) {
double res = 0;
int i;
for(i=0; i <(N+1); i++)
Copy link

Choose a reason for hiding this comment

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

Can be simpler: for(int i = 0; ...)

res = res + Math.pow((N + i), 2);

return res;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,16 @@
public class Task9 {

public static boolean isPowerOfThree(int n) {
return false;
boolean flag = true;
if(n == 0)
Copy link

Choose a reason for hiding this comment

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

<=0

flag = false;
while(n > 1){
if((n % 3) > 0){
flag = false;
break;
} else n = n/3;
}

return flag;
}
}