Методы
This commit is contained in:
@@ -1,29 +0,0 @@
|
|||||||
import java.util.Scanner;
|
|
||||||
|
|
||||||
public class ArrayDemo {
|
|
||||||
|
|
||||||
public static void main(String[] args) {
|
|
||||||
|
|
||||||
Scanner input = new Scanner(System.in);
|
|
||||||
U.pl("За сколько дней выводить температуру ? ");
|
|
||||||
int num = input.nextInt();
|
|
||||||
|
|
||||||
int[] days = new int[num];
|
|
||||||
|
|
||||||
for (int i = 0; i < days.length; i++) {
|
|
||||||
U.pl("Введите температуру за день: " + (i + 1) + ";");
|
|
||||||
days[i] = input.nextInt();
|
|
||||||
}
|
|
||||||
|
|
||||||
int sum = 0;
|
|
||||||
for (int i = 0; i < days.length; i++) {
|
|
||||||
sum += days[i];
|
|
||||||
}
|
|
||||||
|
|
||||||
int average = sum / num;
|
|
||||||
U.pl("Средняя температура за " + num + "дней составила " + average);
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,29 +0,0 @@
|
|||||||
import java.util.Scanner;
|
|
||||||
|
|
||||||
public class DataTypeDemo {
|
|
||||||
public static void main(String[] args) {
|
|
||||||
Scanner sc = new Scanner(System.in);
|
|
||||||
|
|
||||||
while (true) {
|
|
||||||
U.pl(" Введите сумму в доларах: ");
|
|
||||||
double sum = sc.nextDouble();
|
|
||||||
U.pl("Введите символ: e (евро), y (юань), q (выход) ");
|
|
||||||
char operation = sc.next().charAt(0);
|
|
||||||
|
|
||||||
switch (operation) {
|
|
||||||
case 'q':
|
|
||||||
System.out.println(" Выход из программы");
|
|
||||||
break;
|
|
||||||
case 'y':
|
|
||||||
System.out.println(" Вы выбрали юани: сумма " + (sum * 7.23));
|
|
||||||
break;
|
|
||||||
case 'e':
|
|
||||||
System.out.println(" Вы выбрали евро: сумма " + (sum * 0.45));
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
System.out.println(" Неверный код операции ");
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
+7
-13
@@ -1,20 +1,14 @@
|
|||||||
public class Main {
|
public class Main {
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
|
MetodDemo.sayHelloByName("Евгений");
|
||||||
|
MetodDemo.sayHelloByName("Алексей");
|
||||||
|
|
||||||
java.util.Scanner input = new java.util.Scanner(System.in);
|
int sum = MetodDemo.plus(22, 23);
|
||||||
U.pl(" Введите базовую стоимость ремонта одной комнаты ");
|
U.pl("Результат сложения: " + sum);
|
||||||
|
|
||||||
int basePrice = input.nextInt();
|
|
||||||
U.pl(" Введите количество комнат ");
|
|
||||||
int roomCount = input.nextInt();
|
|
||||||
|
|
||||||
|
|
||||||
for (int i = 1; i <= roomCount; i++) {
|
|
||||||
int room = i * basePrice;
|
|
||||||
U.pl("Комната " + i + " стоит " + room);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
int[] myArr = {12, 45, 78, 23, 9};
|
||||||
|
int maximum = MetodDemo.finMax(myArr);
|
||||||
|
U.pl("Самое большое число " + maximum);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,28 @@
|
|||||||
|
public class MetodDemo {
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
|
||||||
|
sayHello();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void sayHello() {
|
||||||
|
System.out.println(" Я изолированный метод");
|
||||||
|
}
|
||||||
|
public static void sayHelloByName(String name){
|
||||||
|
U.pl("Привет, " + name+ " !");
|
||||||
|
}
|
||||||
|
public static int plus (int a, int b){
|
||||||
|
int result = a+b;
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
public static int finMax(int[] number) {
|
||||||
|
int max = number [0];
|
||||||
|
for (int i = 1; i < number.length; i++) {
|
||||||
|
if (number[i] > max) {
|
||||||
|
max = number[i];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return max;
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user