mdsk.net
当前位置:首页 >> jAvA编写程序,找出一维数组中元素的最大值和最小值. >>

jAvA编写程序,找出一维数组中元素的最大值和最小值.

public class Test {public static void main(String[] args) {int[] n = {325,2362,123,6,123,-8,-235,23};getMaxMin(n);}static void getMaxMin(int[] n){int min = Integer.MAX_VALUE;int max = Integer.MIN_VALUE;for(int i=0;in[i]){min = ...

我这儿简单做了下,你看行不. import java.util.Arrays; import java.util.Scanner; public class 输入排序3 { public static void main(String[] args) { System.out.println("请输入10个数据:"); Scanner input=new Scanner(System.in);//输...

public class Max { public static void main(String[] args) { int[] y= {0,9,4,8,2,12,444,5,-1,-22,45}; int max = m(y); int min = mm(y); System.out.println("最大值 "+max); System.out.println("最小值 "+min); System.out.println("差...

package com.test; import java.util.Arrays; public class Test { public static void main(String[] args) { int[] score=new int[5]; int sum=0;//记录所以数据的和 for(int i=0;i

应该是这吧? if(Arr[i]>Arr[j]){ 应该同目前的最大值比较才对. if(Arr[i]>max){ 又或者max取(max,Arr[i],Arr[j])三个中的最大值,而不是仅仅Arr[i],Arr[j]. 最小值应该也是这样. 以上没有考虑效能问题.

import java.util.Arrays; public class Test1 { public static void main(String[] args) { int[] ary = {23, 43, 21, 67, 33, 89, 70}; Arrays.sort(ary); int max = ary[ary.length-1]; int min = ary[0]; System.out.println("最大值是:" +...

public static void main(String[] args) { int[] a=new int[]{6,8,4,9,2}; int min;int max; min=max=a[0]; for(int i=1;ia[i]) min=a[i]; if(max

int []shu ={30,80,96,45,8,35}; for (int i=0;i

int []shu ={30,80,96,45,8,35}; for (int i=0;i

网站首页 | 网站地图
All rights reserved Powered by www.mdsk.net
copyright ©right 2010-2021。
内容来自网络,如有侵犯请联系客服。zhit325@qq.com