Java编程题求助,救救孩子
发布网友
发布时间:2022-05-27 04:57
我来回答
共3个回答
热心网友
时间:2023-10-09 03:47
public static void main(String[] args) {
int min = 0x3f3f3f;//存放最小偶数
int max = 0;//存放最大奇数
int value;
Scanner input = new Scanner(System.in);
int n = input.nextInt();
for(int i = 0;i < n;i ++) {
value = input.nextInt();
if(value%2 == 0) {
if(min > value) {
min = value;//偶数最小值
}
}
else {
if(max < value) {
max = value;//奇数最大值
}
}
}
input.close();
if(max != 0) {
System.out.println("Maxjs-" + max);
}
else {
System.out.println("Maxjs-None");
}
if(min != 0x3f3f3f) {
System.out.println("Minos-" + min );
}
else {
System.out.println("Minos-None");
}
}
热心网友
时间:2023-10-09 03:48
import java.util.*;
public class TestClass {
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
List arr = new ArrayList();
while(n>0){
arr.add(sc.nextInt());
n--;
}
Collections.sort(arr);
System.out.println(arr);
int minOshu = 0;
int maxJshu = 0;
for(int i=0;i<arr.size();i++){
minOshu = Integer.parseInt(arr.get(i).toString());
if(minOshu%2==0){
System.out.println("最小的偶数是:"+arr.get(i).toString());
break;
}
}
for (int i = arr.size()-1; i >0 ; i--) {
maxJshu = Integer.parseInt(arr.get(i).toString());
if(maxJshu%2==1){
System.out.println("最大的奇数是:"+ maxJshu);
break;
}
}
if(minOshu==0){
System.out.println("最小的偶数是:none");
}
if(maxJshu==0){
System.out.println("最大的奇数是:none");
}
}
}
热心网友
时间:2023-10-09 03:48
public class Sy3_2_4 {
public static void main(String[] args) {
int bj = -1
int so = -1
int n = Integer.parseInt(args[0])
for(int i=0;i<n;i++)
{
int now = Integer.parseInt(args[i+1])
if(now %2==1)
{
if (now>bj)
{
bj = now
}
}
else{
if(now<so||so==-1)
so = now
}
}
if(bj != -1)
system.out.println("Max js is "+nj)
else
system.out.println("Max js is None")
if(so != -1)
system.out.println("Min os is "+so)
else
system.out.println("Min os is None")
}
}