参考代码:
import java.util.Arrays;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
int count = scan.nextInt();
int[] arr = new int[count];
for(int i = 0; i < count; i++){
arr[i] = scan.nextInt();
if(arr[i] % 2 == 0){
arr[i] = -1;
}
}
int count1 = 0;
for(int i = 0; i < count; i++){
if(arr[i] > 0){
count1++;
}
}
int[] newArr = new int[count1];
int j = 0;
for(int i = 0; i < count; i++){
if(arr[i] > 0) {
newArr[j] = arr[i];
j++;
}
}
Arrays.sort(newArr);
for(int i = 0; i < count1; i++){
if(i<count1-1){
System.out.print(newArr[i] + ",");
}else{
System.out.print(newArr[i]);
}
}
}
}
0.0分
0 人评分
模拟计算器 (C语言代码)浏览:966 |
简单的a+b (C语言代码)浏览:676 |
2003年秋浙江省计算机等级考试二级C 编程题(2) (C语言代码)浏览:729 |
C语言程序设计教程(第三版)课后习题8.9 (C语言代码)浏览:690 |
A+B for Input-Output Practice (C++代码)浏览:632 |
母牛的故事 (C语言代码)浏览:478 |
【出圈】 (C语言代码)浏览:824 |
淘淘的名单 (C语言代码)浏览:1167 |
C语言程序设计教程(第三版)课后习题11.1 (C语言代码)浏览:651 |
【亲和数】 (C语言代码)浏览:628 |