Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 37
Expand file tree
/
Copy pathascending-array.java
More file actions
Latest commit
35 lines (35 loc) · 935 Bytes
/
Copy pathascending-array.java
File metadata and controls
35 lines (35 loc) · 935 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
importjava.util.Scanner;
publicclassAscending_Order
{
publicstaticvoidmain(String[] args)
{
intn, temp;
Scanners = newScanner(System.in);
System.out.print("Enter no. of elements you want in array:");
n = s.nextInt();
inta[] = newint[n];
System.out.println("Enter all the elements:");
for (inti = 0; i < n; i++)
{
a[i] = s.nextInt();
}
for (inti = 0; i < n; i++)
{
for (intj = i + 1; j < n; j++)
{
if (a[i] > a[j])
{
temp = a[i];
a[i] = a[j];
a[j] = temp;
}
}
}
System.out.print("Ascending Order:");
for (inti = 0; i < n - 1; i++)
{
System.out.print(a[i] + ",");
}
System.out.print(a[n - 1]);
}
}