public class Solution {
public static void main(String[] args) throws Exception {
Scanner sc1 = new Scanner(System.in);
int l;
int y;
int r;
int x = sc1.nextInt();
int[] n = new int[x];
for (l = 0; l<x; l++) {
n[l] = sc1.nextInt();
}
for(l=0; l<x; l++) {
for(y = l +1; y<x; y++) {
if (n[l] > n[y]) {
r = 0;
r = n[l];
n[l] = n[y];
n[y] = r;
}
}
}
for(l = 0; l<x; l++) {
System.out.print(n[l]);
}
System.out.print(n[l]);
}
}
Any hints?
Under discussion
Comments (2)
- Popular
- New
- Old
You must be signed in to leave a comment
Boberno1
21 January 2020, 20:04
Class Arrays has static method to resolve that . (Arrays.sort). It's the simplest way I think.
0
Peter Gray
20 January 2020, 23:15
public class Solution {
public static void main(String[] args) throws Exception {
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
int[] n = new int[5];
for (int i = 0; i < 5; i++) {
n[i] = Integer.parseInt(reader.readLine());
}
for (int i = 0; i < n.length; i++) {
for (int j = i+1; j < n.length; j++) {
if (n[j] < n[i]) {
int temp = n[i];
n[i] = n[j];
n[j] = temp;
}
}
}
for (int k = 0; k < n.length; k++) {
System.out.println(n[k]);
}
}
}
0