Skip to content

Instantly share code, notes, and snippets.

@A-nn-aL
Created September 17, 2021 08:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save A-nn-aL/5e668967b42c62536de646a87a09f476 to your computer and use it in GitHub Desktop.
Save A-nn-aL/5e668967b42c62536de646a87a09f476 to your computer and use it in GitHub Desktop.
package nai196.litvinenko;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.sql.SQLOutput;
import java.util.Scanner;
public class Main {
public static void main(String[] args) throws IOException {
// task 1
System.out.println("Task 1");
task1();
// task 2
//System.out.println("\n Task 2");
Man man = new Man();
Woman woman = new Woman();
man.wife = woman;
woman.husband = man;
// task 3
System.out.println("\n Task 3");
System.out.println(Solution.min(12, 33));
System.out.println(Solution.min(-20, 0));
System.out.println(Solution.min(-10, -20));
// task 4
System.out.println("Task 4");
System.out.println(Solution4.convertToSeconds(6));
System.out.println(Solution4.convertToSeconds(1));
// task 5
System.out.println("\nTask 5");
System.out.println(Solution5.multiplicationTable(1));
System.out.println(Solution5.multiplicationTable(2));
System.out.println(Solution5.multiplicationTable(3));
System.out.println(Solution5.multiplicationTable(4));
System.out.println(Solution5.multiplicationTable(5));
System.out.println(Solution5.multiplicationTable(6));
System.out.println(Solution5.multiplicationTable(7));
System.out.println(Solution5.multiplicationTable(8));
System.out.println(Solution5.multiplicationTable(9));
System.out.println(Solution5.multiplicationTable(10));
// task 6
System.out.println("\nTask 6");
Apple6 apple = new Apple6();
apple.addPrice(50);
Apple6 apple2 = new Apple6();
apple2.addPrice(100);
System.out.println("Стоимость яблок " + Apple6.applesPrice);
// task 7
System.out.println("\nTask 7");
Human human = new Human();
human.setName("Макс");
System.out.println("name: " + human.getName());
// task 8
System.out.println("\nTask 8");
Solution8.checkSeason(12);
Solution8.checkSeason(4);
Solution8.checkSeason(7);
Solution8.checkSeason(10);
//task 11
System.out.println("\nTask 11");
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
String text = "The max is ";
System.out.println("Enter a");
int a = Integer.parseInt(reader.readLine());
System.out.println("Enter b");
int b = Integer.parseInt(reader.readLine());
Max.max(a, b, text);
//task 12
System.out.println("\nTask 12");
int even = 0;
int odd = 0;
System.out.println("Enter positive number ");
BufferedReader reader12 = new BufferedReader(new InputStreamReader(System.in));
int x = Integer.parseInt(reader12.readLine()); // х это число вводимое с клавиатуры
if (x > 0) {
while (x > 0) {
if (x % 2 == 0) {
even++;
} else odd++;
System.out.println(" x " + x);
x /= 10;
}
System.out.println("Even: " + even + " Odd: " + odd);
}
else
System.out.println("number < 0");
//task 13
System.out.println("\nTask 13");
int[] array = new int[10];
int i = 0;
Scanner in = new Scanner(System.in);
for (int element : array) {
System.out.print("[" + (i + 1) + "] ");
array[i] = in.nextInt();
i++;
}
int max = max(array);
System.out.println("Max element: " + max);
}
// task 1
public static void task1() {
for (int i = 0; i < 10; i++) {
System.out.printf("JAVA HOME %d \n", i + 1);
}
}
//task 13
public static int max(int[] array) {
int max = 0;
for (int i = 0; i < array.length; i++) {
if (max < array[i]) {
max = array[i];
}
}
return max;
}
}
//task 2
class Person {
String name;
}
class Man extends Person {
Woman wife;
}
class Woman extends Person {
Man husband;
}
// task 3
class Solution {
public static int min(int a, int b) {
if (a < b) {
return a;
} else if (b < a) {
return b;
} else
return -1;
}
}
//task 4
class Solution4 {
public static int convertToSeconds(int hours) {
return 60 * 60 * hours;
}
}
//task 5
class Solution5 {
public static String multiplicationTable(int number) {
String rez = "";
for (int i = 1; i <= 10; i++) {
int num = i * number;
rez = rez + " " + num;
}
return rez;
}
}
// task 6
class Apple6 {
public static int applesPrice = 0;
public void addPrice(int applesPrice) {
this.applesPrice += applesPrice;
}
}
// task 7
class Human {
private String name = "человек";
public void setName(String name) {
this.name = name;
}
public String getName() {
return name;
}
}
// task 8
class Solution8 {
public static void checkSeason(int month) {
if (month < 1 || month > 12)
System.out.println("There are only 12 months in this universe (1-12)");
switch (month) {
case 1, 2, 12 -> System.out.println(month + " Winter");
case 3, 4, 5 -> System.out.println(month + " Spring");
case 6, 7, 8 -> System.out.println(month + " Summer");
case 9, 10, 11 -> System.out.println(month + " Autumn");
}
}
}
// task 9
class Human9 {
String name;
int age;
int weight;
int strength;
}
// task 10
class Dog {
String name;
int age;
public void setName(String name) {
this.name = name;
}
public void setAge(int age) {
this.age = age;
}
public int getAge() {
return this.age;
}
public String getName() {
return this.name;
}
}
// task 11
class Max {
public static void max(int a, int b, String text) {
int max;
if (a > b) {
max = a;
System.out.println(text + max);
} else if (b > a) {
max = b;
System.out.println(text + max);
} else {
System.out.println("The numbers are equal");
}
}
}
@Truewaydm
Copy link

Просмотрел

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment