-
Notifications
You must be signed in to change notification settings - Fork 0
/
oddnumbers10(3).java
35 lines (31 loc) · 992 Bytes
/
oddnumbers10(3).java
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
class AscOddnumbers
{
public static void main(String args[])
{
int [] arr = new int [] {5,1,7,3,11,9,13,17,15};
int temp = 0;
System.out.println("Given odd numbers: ");
for (int i = 0; i < arr.length; i++)
{
System.out.print(arr[i] + " ");
}
for (int i = 0; i < arr.length; i++)
{
for (int j = i+1; j < arr.length; j++)
{
if(arr[i] > arr[j])
{
temp = arr[i];
arr[i] = arr[j];
arr[j] = temp;
}
}
}
System.out.println();
System.out.println("odd numbers in ascending order: ");
for (int i = 0; i < arr.length; i++)
{
System.out.print(arr[i] + " ");
}
}
}