-
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
homework1 #10
base: master
Are you sure you want to change the base?
homework1 #10
Changes from all commits
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,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) | ||
flag = false; | ||
while((a/10) > 0){ | ||
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 can be just |
||
aLast = a%10; | ||
a = a/10; | ||
if((aLast == 2)|(a == 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 better to use |
||
flag = true; | ||
break; | ||
} | ||
} | ||
return flag; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 |
---|---|---|
|
@@ -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))) | ||
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.
|
||
return true; | ||
else return false; | ||
|
||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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){ | ||
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 use |
||
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 |
---|---|---|
|
@@ -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))); | ||
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. Can be just |
||
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){ | ||
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 change it to |
||
int result; | ||
if (n==1) return 1; | ||
result = factorial(n-1)*n; | ||
return result; | ||
} | ||
|
||
public double calculateS(double x) { | ||
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. The same, please add |
||
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 |
---|---|---|
@@ -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++) | ||
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. Can be simpler: |
||
res = res + Math.pow((N + i), 2); | ||
|
||
return res; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,16 @@ | |
public class Task9 { | ||
|
||
public static boolean isPowerOfThree(int n) { | ||
return false; | ||
boolean flag = true; | ||
if(n == 0) | ||
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.
|
||
flag = false; | ||
while(n > 1){ | ||
if((n % 3) > 0){ | ||
flag = false; | ||
break; | ||
} else n = n/3; | ||
} | ||
|
||
return flag; | ||
} | ||
} |
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.
No need in this verification and assignment because your flag is already set to false.