Skip to content
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
5 changes: 1 addition & 4 deletions task01/src/com/example/task01/Task01.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,7 @@
public class Task01 {

public static String solution() {

// TODO напишите здесь свою корректную реализацию этого метода, вместо сеществующей

return "здесь какая-то неправильная строка";
return "Я думаю, быть программистом - это круто";
}

public static void main(String[] args) {
Expand Down
13 changes: 10 additions & 3 deletions task02/src/com/example/task02/Task02.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,17 @@
public class Task02 {

public static String solution(String input) {
try {
long value = Long.parseLong(input);

// TODO напишите здесь свою корректную реализацию этого метода, вместо сеществующей
if (value >= -128 && value <= 127) return "byte";
if (value >= -32768 && value <= 32767) return "short";
if (value >= -2147483648L && value <= 2147483647L) return "int";
return "long";

return "";
} catch (NumberFormatException e) {
return "long";
}
}

public static void main(String[] args) {
Expand All @@ -18,4 +25,4 @@ public static void main(String[] args) {
*/
}

}
}
7 changes: 2 additions & 5 deletions task03/src/com/example/task03/Task03.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,7 @@
public class Task03 {

public static int getMetreFromCentimetre(int centimetre) {

// TODO напишите здесь свою корректную реализацию этого метода, вместо сеществующей

return 0;
return centimetre / 100;
}

public static void main(String[] args) {
Expand All @@ -18,4 +15,4 @@ public static void main(String[] args) {
*/
}

}
}
18 changes: 13 additions & 5 deletions task04/src/com/example/task04/Task04.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,18 @@
public class Task04 {

public static float calculate(int a, int b, String operation) {

// TODO напишите здесь свою корректную реализацию этого метода, вместо сеществующей

return 0;
switch (operation) {
case "+":
return (float) a + b;
case "-":
return (float) a - b;
case "*":
return (float) a * b;
case "/":
return (float) a / b;
default:
return 0;
}
}

public static void main(String[] args) {
Expand All @@ -18,4 +26,4 @@ public static void main(String[] args) {
*/
}

}
}
12 changes: 8 additions & 4 deletions task05/src/com/example/task05/Task05.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,14 @@
public class Task05 {

public static String solution(int x) {

// TODO напишите здесь свою корректную реализацию этого метода, вместо сеществующей

return "FALSE";
while (x > 0) {
int digit = x % 10;
if (digit % 2 != 0) {
return "FALSE";
}
x /= 10;
}
return "TRUE";
}

public static void main(String[] args) {
Expand Down
6 changes: 2 additions & 4 deletions task06/src/com/example/task06/Task06.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,8 @@
public class Task06 {

public static int solution(int x, int y) {

// TODO напишите здесь свою корректную реализацию этого метода, вместо сеществующей

return 0;
int sum = x + y;
return String.valueOf(Math.abs(sum)).length();
}

public static void main(String[] args) {
Expand Down
7 changes: 2 additions & 5 deletions task07/src/com/example/task07/Task07.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,7 @@
public class Task07 {

public static int solution(int n, int m, int k) {

// TODO напишите здесь свою корректную реализацию этого метода, вместо сеществующей

return 0;
return (n / k) * (m / k);
}

public static void main(String[] args) {
Expand All @@ -18,4 +15,4 @@ public static void main(String[] args) {
*/
}

}
}
5 changes: 2 additions & 3 deletions task08/src/com/example/task08/Task08.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,11 @@
public class Task08 {

public static boolean solution() {
// TODO измените тип и значение переменной x, чтобы возвращалось значение true

int x = 100;
float x = 1e30f;
return x == x + 1;
}


public static void main(String[] args) {
// Здесь вы можете вручную протестировать ваше решение
/*
Expand Down
4 changes: 1 addition & 3 deletions task09/src/com/example/task09/Task09.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,9 @@
public class Task09 {

public static double solution() {
// TODO Устраните ошибку вычисления выражения, не изменяя типы данных у переменных

float a = 1.0f;
float b = 3.0f;
double x = (a / b - 1.0 / 3.0) * 1.0e9;
double x = ((double)a / b - 1.0 / 3.0) * 1.0e9;

return x;
}
Expand Down
15 changes: 8 additions & 7 deletions task10/src/com/example/task10/Task10.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@
public class Task10 {

public static boolean compare(float a, float b, int precision) {

// TODO корректно сравнивать два значения типа float с заданной пользователем точностью (параметр - количество знаков после запятой).
// Функция должна корректно обрабатывать ситуацию со сравнением значений бесконечности.
// Функция должна считать значения «не число» NaN (например 0.0/0.0) равными между собой.

return a == b;

if (Float.isNaN(a) && Float.isNaN(b)) return true;
if (Float.isNaN(a) || Float.isNaN(b)) return false;
if (Float.isInfinite(a) || Float.isInfinite(b)) {
return a == b;
}

double epsilon = Math.pow(10, -precision);
return Math.abs(a - b) < epsilon;
}

public static void main(String[] args) {
Expand Down
9 changes: 1 addition & 8 deletions task11/src/com/example/task11/Task11.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,7 @@
public class Task11 {

public static float benefit(float sum, float percent) {

// TODO исправьте функцию, чтобы избежать накопления ошибки

// Считаем проценты за год
for (int i = 1; i <= 12; i++) {
sum += sum * percent;
}
return sum;
return (float)(sum * Math.pow(1.0 + percent, 12));
}

public static void main(String[] args) {
Expand Down
16 changes: 6 additions & 10 deletions task12/src/com/example/task12/Task12.java
Original file line number Diff line number Diff line change
@@ -1,23 +1,19 @@
package com.example.task12;

import java.math.BigDecimal;
import java.math.RoundingMode;

public class Task12 {

public static BigDecimal benefit(BigDecimal sum, BigDecimal percent) {
int intermediateScale = 18;
BigDecimal result = sum.setScale(intermediateScale, RoundingMode.HALF_UP);

// TODO раскомментируйте и исправьте код

// Считаем проценты за год

/*
for (int i = 1; i <= 12; i++) {
sum += sum * percent;
for (int i = 0; i < 12; i++) {
result = result.add(result.multiply(percent).setScale(intermediateScale, RoundingMode.HALF_UP));
}
return sum;
*/

return BigDecimal.ZERO;
return result.setScale(9, RoundingMode.HALF_UP);
}

public static void main(String[] args) {
Expand Down
6 changes: 3 additions & 3 deletions task13/src/com/example/task13/Task13.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
public class Task13 {

public static char toUpperCase(char c) {

// TODO привести букву к верхнему регистру

if (c >= 'a' && c <= 'z') {
return (char)(c - 32);
}
return c;
}

Expand Down
7 changes: 3 additions & 4 deletions task14/src/com/example/task14/Task14.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,9 @@ public class Task14 {


public static int reverse(int value) {

// TODO напишите здесь код, переставляющий цифры числа в обратном порядке

return 0;
String str = Integer.toString(value);
String reversedStr = new StringBuilder(str).reverse().toString();
return Integer.parseInt(reversedStr);
}

public static void main(String[] args) {
Expand Down