Given a sequence of positive integers of length N (not greater than 500), take out all odd numbers and output them in ascending order.
enter
2 lines in total:
Line 1 N;
Line 2 contains N positive integers separated by spaces. output
Odd sequence of output in ascending order, separated by commas.
The data is guaranteed to have at least one odd number.
Sample input
10
1 3 2 6 5 4 9 8 7 10
Sample output
1,3,5,7,9
import java.util.Arrays;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scan=new Scanner(System.in);
int n,i,j=0,k,m=0;
n=scan.nextInt();
int[] a=new int[n];
for(i=0;i<n;i++)
a[i]=scan.nextInt();
for(i=0;i<n;i++){
if(a[i]%2!=0)
m++;
}
int[] b=new int[m];
for(i=0;i<n;i++){
if(a[i]%2!=0)
b[j++]=a[i];
}
Arrays.sort(b);
for(i=0;i<m;i++){
if(i!=m-1)
System.out.print(b[i]+",");
else
System.out.print(b[i]);
}
}
}