华恩JAVA班第12天

xiaoxiao2021-02-28  85

华恩JAVA班第12天

一 基本类型:基本类型,或者叫做内置类型,是JAVA中不同于类的特殊类型。

数据类型 大小 范围 默认值 byte(字节) 8 -128 - 127 0 shot(短整型) 16 -32768 - 32768 0 int(整型) 32 -2147483648-2147483648 0 long(长整型) 64 -9233372036854477808-9233372036854477808 0 float(浮点型) 32 -3.40292347E+38-3.40292347E+38 0.0f double(双精度) 64 -1.79769313486231570E+308-1.79769313486231570E+308 0.0d char(字符型) 16 ‘ \u0000 - u\ffff ’ ‘\u0000 ’ boolean(布尔型) 1 true/false false 包装类型:包装类型/引用 int        Integer long       Long float      Float double     Double byte       Byte ...        ... 二、 基本类型比较:==   内存地址比较 引用类型比较:equals  值比较 ==: public class Test {  public static void main(String[] args)  {   int a = 1,b = 1;   Integer c = 1;   Integer d = new Integer(1); //new 强制开辟一个空间   Integer e = new Integer(1);   Integer f = c;   System.out.println(c == d);// c与d的地址不同,   System.out.println(c.equals(d)); // 值比较   System.out.println(c == b);   System.out.println(b == d);   System.out.println(c == f);   System.out.println(e == d);  } } equals: class Dog{   String name;   String zl;   public boolean equals(Object anObject){    if(this == anObject){     return true;    }    if(anObject instanceof Dog){     Dog dog = (Dog) anObject;    if(dog.name.equals(this.name)){     return true;    }else{     return false;    }    }else{    return false;    }   } } public class Test2 {  public static void main(String[] args){   Dog dog1 = new Dog();   Dog dog2 = new Dog();   dog1.name = "tom";   dog2.name = "tom";   dog1.zl = "哈士奇";   dog2.zl = "哈士奇";   System.out.println(dog1.equals(dog2));  } } 三、 import java.util.*; public class Test {  public static void main(String[] args){   Scanner in =new Scanner(System.in);   int A = in.nextInt();   for(int a = 0 ;a <= A;a++){    for(int b = 0;b < A-a+1;b++){     System.out.print(" ");    }    for(int i = 0;i < 2*a-1;i++){          System.out.print("*");    }    System.out.println();   }  } }
转载请注明原文地址: https://www.6miu.com/read-74834.html

最新回复(0)