• 数组


     1 //数组元素求最值,反转
     2 public class Array {
     3     public static void main(String[] args) {
     4         int[] array=new int[]{50,47,68,24,100};
     5         int max,min;
     6         max=min=array[0];
     7         for(int i=1;i<array.length;i++)
     8         {if(array[i]>max)
     9                 max=array[i];
    10             if(array[i]<min)
    11                 min=array[i];}
    12         System.out.println("最大值:"+max);
    13         System.out.println("最小值:"+min);
    14         int i=0;
    15         int right=array.length-1;
    16         for(;i<array.length/2;i++,right--)
    17         {int t=array[i];
    18         array[i]=array[right];
    19         array[right]=t;}
    20         for (i = 0; i < array.length; i++) {
    21             System.out.println(array[i]);
    22         }
    23 
    24     }
    25 }
    26 -----------------------------
    27 最大值:100
    28 最小值:24
    29 100
    30 24
    31 68
    32 47
    33 50
    34 
    35 Process finished with exit code 0

    数组作为函数的返回值(地址传递)

     1 public class Methodarray {
     2     public static void main(String[] args) {
     3         double[] a=cal(2.2,3.5,6.8);
     4         System.out.println(a[0]);
     5         System.out.println(a[1]);
     6         
     7     }
     8     public static double[] cal(double a,double b,double c){
     9         double[] array={a+b+c,(a+b+c)/3};
    10         return array;
    11     }
    12 }
    13 ----------------------------------------------
    14 12.5
    15 4.166666666666667
    16 
    17 Process finished with exit code 0

    return语句只能返回一个,但使用数组,可返回数组地址,间接返回多个值

  • 相关阅读:
    GJM : Unity的profiler性能分析【转载】
    GJM :Unity UI 之 UGUI 开发
    GJM:笔记记录
    GJM : UGUI 缩放循环拖动展示卡牌效果
    GJM :HTC Vive VRTK.Package 踩坑之路(一)
    GJM :Mono 介绍
    GJM :Unity3D 介绍
    GJM : C# 介绍
    GJM : 通用类型系统(Common Type System CTS)
    GJM :SQL Server中常用的SQL语句
  • 原文地址:https://www.cnblogs.com/XiaoJin0/p/10538326.html
Copyright © 2020-2023  润新知