www.dbpj.net > jAvA编程:计算一个一维数组中的最大值和最小值及...

jAvA编程:计算一个一维数组中的最大值和最小值及...

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("最大值是:" + max); system.out.println("最

java编写程序,找出一维数组中元素的最大值和最小值:方法1:import java.util.*; public class Main{ public static void main (String args[ ]) { int a1[ ]=new int[] {5,3,6,8,10,56}; Arrays.sort(a1); System.out.println("最大值:"+a1[a1.length-1]);

class arr { double num[]; public arr(double n[]) { num = new double[n.length]; for(int i=0;inum[i])//最小值 { m[1]=num[i]; } } return m; } } public class test { public static void main

public static void main(String[] args) { // TODO Auto-generated method stub int arr[]={20,50,80,70,65,746,38}; int min=arr[0]; int max=arr[0]; int sum=0; for(int i=0;i<arr.length;i++){ if(max<arr[i]){ max=arr[i]; } if(min>arr[i]){ min=arr[i]; } sum+=arr[i];

public class test16 { /** * @param args */ public static void main(String[] args) { // TODO Auto-generated method stub int[] a=new int[10];//定义初始化一个10元素的整型数组a int max; int min; for(int i=0;i<9;i++){ a[i]=(int)(10*Math.random());//取10

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("最大值是:" + max); system.out.println("最

#include "stdio.h" void main() {int a[50],i,j,t,n;<br> printf("请要输入的整数个数:"); <br> scanf("%d",&n);<br> printf("请输入%d整数:",n);<br> for(i=0;i<n;i++)<br> scanf("%d",&a[i]);</p><p> for(i=0;i<n-1;i++)<br> for(j=0;j<n-i;

package test; public class Test { public static void main(String[] args) { int[] nums = { 2, 1, 4, 100, 88, 66, 123, 5, 74, 69 }; for (int i = 0; i <= nums.length - 1; i++) { for (int j = i + 1; j <= nums.length - 1; j++) { if (nums[i] > nums[j]) { int temp = nums[i]; nums[

int a[n];//数组int tmp=0;//临时变量for(int i=0;i<n;++i)for(int j=0;j<n-1;++j){ if(a[j]>a[j+1])//满足条件交换,大于或者小于改变就是升序或者降序. { tmp=a[j]; a[j]=a[j+1] a[j+1]=tmp; }}//这是一个完全不考虑效率的冒泡排序.应该比较好理解..排序后数组有序..然后 0 与n就是最大与最小..我是直接在上面打的..所以有点不工整..你加个主方法然后调试一下..有问题给我说

int a[5]={3,7,6,5,4}; int max=min-a[0]; int dif; for(int i=0;i<5;i++) { if(a[i+1]>max){max=a[i+1]}; if(a[i+1]<min){min=a[i+1]}; } dif=max-min;//max,min,dif分别是最大值,最小值和差值

网站地图

All rights reserved Powered by www.dbpj.net

copyright ©right 2010-2021。
www.dbpj.net内容来自网络,如有侵犯请联系客服。zhit325@qq.com