• Arrays与Math类


    ## Arrays类中一些方法的使用

    ```java
    import java.util.Arrays; //一个数组相关的工具类,提供了大量静态方法用来实现数组相关操作
    import java.util.Random;
    /*
    1.public static String toString(数组);
    将参数数组变成字符串,按照默认格式【元素1,元素2....】
    2.public static void sort(数组);
    按照默认升序对数组进行排序
    */
    public class LLArrays {
    public static void main(String[] args){

    //随机生成一个具有十个元素的数组
    Random r = new Random();
    int[] nums = new int[10];
    int num = 0;
    for(int i=0;i<nums.length;i++){
    num = r.nextInt(66);
    nums[i] = num;
    }

    System.out.println("原数组:");
    for(int i=0;i<nums.length;i++){
    System.out.print(nums[i]+" ");
    }

    System.out.println();
    String str1 =Arrays.toString(nums);
    System.out.println(str1);
    //调用Arrays类中的toString方法,并输出改变后的字符串

    Arrays.sort(nums);
    for(int i=0;i<nums.length;i++){
    System.out.print(nums[i]+" ");
    }
    //调用sort对·生成的数组进行排序,并输出
    }
    }
    ```

    ## Math类的一些方法


    /*
    Math常用方法
    1.public static double abs (double num);获取绝对值
    2.public static double ceil(double num);向上取整
    3.public static double floor (double num);向下取整
    4.public static long round (double num);四舍五入
    //Math。PI代表圆周率常量
    */
    /*
    1.货车拉货:
    共有50吨货物,3.3吨,问需要多少辆(n)货车可以一次拉完;
    最后一辆汽车拉几吨货物y;

    */

    import java.lang.Math;//"lang"可以不用导包,即该语句可以省略
    public class LLmath {
    public static void main(String[] args){
    double to = 50,a = 3.3;
    double x = to/a;
    double y = 0;
    double n=0;
    n = Math.ceil(x);
    System.out.println("x:"+x);
    System.out.println("n:"+n);
    if(n!=x) y= to -Math.floor(x)*a;
    else y = 3.3;
    System.out.println("y:"+y);
    }
    }
  • 相关阅读:
    【2012】笔试面试总结(二)
    sdf数据文件查看小工具
    excel表格中怎样使个别单元格变成只读
    平时收获,供需及取(PPC)
    GDI+ 绘制统计图(2D、3D)
    Com注册
    Pocket PC 录音
    我有自己的"CodeSnippet"了!
    打包Winows Mobile快捷方式中文问题?
    ORA12154: TNS: 无法解析指定的连接标识符问题解决
  • 原文地址:https://www.cnblogs.com/susexuexi011/p/13763101.html
Copyright © 2020-2023  润新知