Работа была сделана с помощью сайта Jdoodle.
Сортировка пузырьковым методом
import java.util.Arrays;
public class Main {
public static void main(String[] args) {
int [] mas = {7, 15, 100, 500, 71};
boolean isSorted = false;
int b;
while(!isSorted) {
isSorted = true;
for (int i = 0; i < mas.length-1; i++) {
if(mas[i] > mas[i+1]){
isSorted = false;
b = mas[i];
mas[i] = mas[i+1];
mas[i+1] = b;
}
}
}
System.out.println(Arrays.toString(mas));
}
}
- Создаем массив чисел
- Обозначаем переменную для обозначения отсортированного массива и для перемещения чисел
- Запускаем цикл
- Заменяем числа, если удовлетворяется условие: левое число > правого
- Выводим результат на экран
Создание класса и класса-наследника
class Clothes {
private String type;
private String color;
public String getType(){ return type; }
public String getColor(){ return color; }
public Clothes(String type, String color){
this.type=type;
this.color=color;
}
public void display(){
System.out.println("Type: " + type);
System.out.println("Color: " + color);
}
}
class Blouse extends Clothes{
private String season;
public Blouse(String type, String color, String season) {
super(type, color);
this.season=season;
}
public void study(){
System.out.printf("%s collection %s \n", getType(), season);
}
}
public class People{
public static void main(String[] args) {
Blouse sandro = new Blouse("Sandro","red", "summer");
sandro.display();
sandro.study();
}
}
- Создаем класс Одежда с характеристиками тип и цвет
- Создаем класс-потомок «Блуза» с наследованием методов
- Создаем конкретный объект фирмы Sandro летней коллекции


Оставьте комментарий