Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.javarush.test.level07.lesson12.bonus03;
- import java.io.BufferedReader;
- import java.io.InputStreamReader;
- /* Learning and practicing algorithm.
- Task: Read from the keyboard 20 numbers and display them in descending order.
- */
- public class Solution
- {
- public static void main(String[] args) throws Exception
- {
- BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
- int N = 20;
- int [] array = new int[N];
- for (int i = 0; i < array.length; i++) {
- array[i] = Integer.parseInt(reader.readLine());
- }
- array = sort(array);
- for (int el : array) {
- System.out.print(el + " ");
- }
- }
- public static int[] sort(int[] a)
- {
- int [] temp = new int[a.length];
- for (int i = 0; i < a.length; i++) {
- temp[i] = a[i];
- }
- boolean isSorted;
- do {
- isSorted = false;
- for (int i = 0; i < temp.length - 1; i++) {
- if (temp[i + 1] > temp[i]) {
- int t = temp[i];
- temp[i] = temp[i + 1];
- temp[i + 1] = t;
- isSorted = true;
- }
- }
- } while (isSorted);
- return temp;
- }
Add Comment
Please, Sign In to add comment