java学习总结——第四天(下)

关系运算符

==   != >  <

>= <=


算数运算符

+ - * / %


自运算

++ --


复合运算

+= -= *= /= %=


逻辑运算符

&&   || ! ^ | &


三元:      ?   =

public class Test{

public static void main(String[] s){

int i1=10,i2=20;

int i=i2++;

System.out.print(" i=" +i);

System.out.println(" i2=" +i2);

i=++i2;

System.out.print(" i=" +i);

System.out.println(" i2=" +i2);

i=--i1;

System.out.print(" i=" +i);

System.out.println(" i2=" +i);

i=i1--;

System.out.print(" i=" +i);

System.out.println(" i1=" +i1);

boolean a,b,c;

a=true;b=false;

c=a&b;System.out.println(c);

c=a|b;System.out.println(c);

c=a^b;System.out.println(c);

c=!a;System.out.println(c);

c=a&&b;System.out.println(c);

c=a||b;System.out.println(c);

}

}

 

Java==运算与地址有关,是判断地址是否相等

New   创建或新造内存存放

public class String1{

public static void main(String[] s){

String s1="abcd";

String s2="abcd";

String s3=new String("abcd");

String s4=new String("abcd");

System.out.println(s1==s2);

System.out.println(s1==s3);

System.out.println(s1.equals(s3));

System.out.println(s2.equals(s4));

}

}

 


随机类 Math.random()  输出(1.0~0.0)不包含两边

public class Mathrandom{

public static void main(String[] s){

char c=(char)(Math.random()*26+'A');

System.out.println(c);

}

}

For循环与数组

  For循环的新格式

for(int y:i){

System.out.println(y);

}

等价于

for(int a=0;a<i.length;a++){

int y=i[a];

System.out.println(y);

}

申请数组语法:

int[] i;

int[] i={};

int[] i=new int[50];

int[] i=new int[]{2,4,54,5};

public class For{

public static void main(String[] s){

int[] i={132,54,4,345,345,3245,32,54,325,325,34,12,315,5456,545,545,65,54,545};

for(int a=0;a<i.length;a++){

System.out.print(i[a]+" ");

}

System.out.println();

System.out.println("000000000000000000000000000000000000000000000000");

for(int y:i){

System.out.print(y+" ");

}

System.out.println();

                System.out.println("000000000000000000000000000000000000000000000000000000000");

int[][][] x={

   {

{321,54,651,465,465,16554},

{1541,5465,561,65},

{2165,5,41}

   },

   {

{12,5,5,12,2123,1},

{456,5,2,2,4,4},

{1,2,65,12}

   }

};

for(int[][] b:x){

    for(int[] c:b){

for(int d:c){

System.out.print(d+" ");

}

    System.out.println();

    }

System.out.println("00000000000000000000000000000");

}

}

}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值