本文介绍了如何从java中的数组中打印max even even和max odd,min even和min odd?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

package lesson5;

import java.util.Scanner;

public class task55 {

	private static Scanner sc;

	public static void main(String[] args) {
		sc = new Scanner(System.in);
		int i = 0;
		double num[] = new double[5];
		double min_even = 0;
		double evencount = 0;
		double evensum = 0;
		int oddcount = 0;
		int oddsum = 0;

		for (i = 0; i < 5; i++) {
			System.out.println("input number");
			num[i] = sc.nextInt();
		}

		System.out.println(" print even num : ");

		for (i = 0; i < 5; i++) {
			if (num[i] % 2 == 0) {

				evencount++;
				evensum += num[i];
				System.out.println(num[i] + " ;");
				if (min_even > num[i])
					min_even = num[i];

			}
		}

		System.out.println(" evencount = " + evencount);
		System.out.println(" evensum =" + evensum);
		System.out.println(" ceven average = " + evensum / evencount);
		System.out.println("-------------------------------");
		System.out.println(" print odd num :");

		for (i = 0; i < 5; i++) {
			if (num[i] % 2 != 0) {
				oddcount++;
				oddsum += num[i];
				System.out.println(num[i] + " ;");

			}
		}

		System.out.println(" oddcount " + oddcount);
		System.out.println(" oddsum =" + oddsum);
		System.out.println(" average odd = " + oddsum / oddcount);

	}
}





我的尝试:



hi,

上面提到的代码可以工作。



但我无法打印通过扫描仪输入阵列的最大和最小偶数和ood数字。



请帮我修复它。



What I have tried:


above mentioned code works.

but i couldnot print max and min even and ood numbers which input to array via scanner.

please help me to reslove it.

推荐答案


这篇关于如何从java中的数组中打印max even even和max odd,min even和min odd?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-03 18:27