• 1月8日 作业


    1. 遍历输出

    public class shuzu2 {
    
        public static void main(String[] args) {
            // TODO 自动生成的方法存根
    
            
            int arr[] = new int [] {35,21,48,66,12,3,90,6};
            //System.out.println(arr.length);
            
            //遍历方法一
            for (int a : arr)
            {
                System.out.println(a);
            }
            
            /*输出结果:
            35
            21
            48
            66
            12
            3
            90
            6*/
            
            
            
            //遍历方法二
            for (int b = 0; b <  arr.length; b++)
            {
                System.out.println("arr"+"["+b+"]="+arr[b]);
            }
            
            /*输出结果:
            arr[0]=35
            arr[1]=21
            arr[2]=48
            arr[3]=66
            arr[4]=12
            arr[5]=3
            arr[6]=90
            arr[7]=6*/
    }
    }

    2  输出数组中最大的数

    public class shuzu2 {
    
        public static void main(String[] args) {
            // TODO 自动生成的方法存根
    
    
                    int arr[] = new int [] {35,21,48,66,12,3,90,6};
    
                    int max = arr[0];
            
            for (int j = 0; j < arr.length;j++)
            {
                if(max < arr[j])
                {
                    max = arr[j];
                }
                
            }
            System.out.println("数组中最大的数是"+max);
            
            
            
            
        }
    
    }
  • 相关阅读:
    第三次jsp作业
    快速排列 使用链表
    Cross
    题目
    ranch
    robot
    Mold
    Mold2
    OX_pattern
    KSC sort
  • 原文地址:https://www.cnblogs.com/yifangtongxing/p/5114328.html
Copyright © 2020-2023  润新知