zoukankan      html  css  js  c++  java
  • Static、Arrays、Math

     1 public class ST01 {
     2 
     3     private String name;
     4     private int age;
     5     private int sid;
     6 
     7     public static int studentNum = 0;
     8 
     9     public ST01(String name, int age) {
    10         this.name = name;
    11         this.age = age;
    12         this.sid = ++ studentNum;
    13     }
    14 
    15     /**
    16      * 当  static 修饰成员变量时,该变量称为类变量。该类的每个对象都共享同一个类变量的值。任何对象都可以更改
    17      * 该类变量的值,但也可以在不创建该类的对象的情况下对类变量进行操作
    18      * */
    19 
    20     /**
    21      * 静态方法
    22      * 当 static 修饰成员方法时,该方法称为类方法 。静态方法在声明中有 static ,建议使用类名来调用,而不需要
    23      * 创建类的对象。调用方式非常简单。
    24      * 类方法 :使用 static关键字修饰的成员方法,习惯称为静态方法。
    25      * */
    26 
    27     public static void showNum(){
    28         System.out.println(studentNum);
    29     }
    30     public void show(){
    31         System.out.println(name + age + sid);
    32     }
    33 
    34     public static void main(String[] args) {
    35         ST01 st = new ST01("WANG", 20);
    36         ST01 st2 = new ST01("WANG1", 22);
    37         ST01 st3 = new ST01("WANG21", 2220);
    38 
    39         st.show();
    40         st2.show();
    41         st3.show();
    42 
    43         ST01.showNum();
    44     }
    45 }
     1     public static void main(String[] args) {
     2         /**
     3          * 将数组转化为字符串
     4          * */
     5 
     6         int[] array = {60, 10, 20, 30, 40};
     7 
     8         String s = Arrays.toString(array);
     9         System.out.println(s);
    10 
    11         /**
    12          * 排序
    13          * */
    14         Arrays.sort(array);
    15         System.out.println(Arrays.toString(array));
            double m = Math.abs(-5);
            double m1 = Math.ceil(3.2);
            double m2 = Math.floor(3.3);
            double m3 = Math.round(3.66);
    
            System.out.println(m);
            System.out.println(m1);
            System.out.println(m2);
            System.out.println(m3);
  • 相关阅读:
    HTML颜色表
    grid
    DOM和BO
    注册表
    js 正则表达式
    python学习之路(一)
    python学习之路(三)
    python学习之路(二)
    自己编写的泛型集合类(其实是照着微软的List写的)
    客户端回调服务端无刷新事件
  • 原文地址:https://www.cnblogs.com/xiaoxiaolulu/p/11326975.html
Copyright © 2011-2022 走看看