package com.codegym.task.task07.task0728;
import java.io.BufferedReader;
import java.io.InputStreamReader;
/*
In decreasing order
*/
public class Solution {
public static void main(String[] args) throws Exception {
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
int[] array = new int[20];
for (int i = 0; i < 20; i++) {
array[i] = Integer.parseInt(reader.readLine());
}
sort(array);
for (int x : array) {
System.out.println(x);
}
}
public static void sort(int[] array) {
//write your code here
int temp=0;
for(int i=0;i<array.length;i++){
help..how to make this array in decreasing order
Under discussion
Comments (4)
- Popular
- New
- Old
You must be signed in to leave a comment
Slawek
3 April 2020, 19:16
You can read about Collections class i Java docs. Some usefull methods - sort, reveseOrder.
0
Stefan Maric
3 April 2020, 13:19
In sort method you will need make nested for loop, and in that loop you will compare values from your array by conditions. Other words:
for (loop 1)
for (loop 2)
if(array[loop1] >= array[loop2]) {
int x = array[loop1]
array[loop1] = array[loop2]
array[loop2] = x
}
I couldn't help you more than this. Use this pattern and you will have solution. Good coding.
0
Hendra
10 April 2020, 03:59
thanks maric..this really help
0
Stefan Maric
11 April 2020, 13:35
No worries, glad I can help. Mark comment as a solution so others can use your problem as help for their solution. Feel free to as for more help.
0