вызовы методов из класса

This commit is contained in:
Евгений
2026-06-17 11:35:12 +03:00
parent e87e59c091
commit 8c12a55684
2 changed files with 37 additions and 8 deletions
+13
View File
@@ -9,6 +9,19 @@ public class Main {
int[] myArr = {12, 45, 78, 23, 9}; int[] myArr = {12, 45, 78, 23, 9};
int maximum = MetodDemo.finMax(myArr); int maximum = MetodDemo.finMax(myArr);
U.pl("Самое большое число " + maximum); U.pl("Самое большое число " + maximum);
int phonePrice = MetodDemo.calculatedDiscount(50000, 10);
U.pl("Цена телефона со скидкой: " + phonePrice);
int laptopPrice = MetodDemo.calculatedDiscount(120000, 20);
U.pl("Цена ноутбука со скидкой: " + laptopPrice);
int userAge = 17;
if (MetodDemo.checkAsses(userAge)) {
U.pl("Доступ запрещен, вам нет 18! ");
} else {
U.pl("Доступ разрешен.Добро пожаловать!");
}
} }
} }
+18 -2
View File
@@ -1,21 +1,22 @@
public class MetodDemo { public class MetodDemo {
public static void main(String[] args) { public static void main(String[] args) {
sayHello(); sayHello();
} }
public static void sayHello() { public static void sayHello() {
System.out.println(" Я изолированный метод"); System.out.println(" Я изолированный метод");
} }
public static void sayHelloByName(String name) { public static void sayHelloByName(String name) {
U.pl("Привет, " + name + " !"); U.pl("Привет, " + name + " !");
} }
public static int plus(int a, int b) { public static int plus(int a, int b) {
int result = a + b; int result = a + b;
return result; return result;
} }
public static int finMax(int[] number) { public static int finMax(int[] number) {
int max = number[0]; int max = number[0];
for (int i = 1; i < number.length; i++) { for (int i = 1; i < number.length; i++) {
@@ -25,4 +26,19 @@ public class MetodDemo {
} }
return max; return max;
} }
public static int calculatedDiscount(int price, int percent) {
int discountAmount = (price * percent) / 100;
int finalPrice = price - discountAmount;
return finalPrice;
}
public static boolean checkAsses (int age) {
if (age < 18) {
return true;
} else {
return false;
}
}
} }