关系运算符
== != > <
>= <=
算数运算符
+ - * / %
自运算
++ --
复合运算
+= -= *= /= %=
逻辑运算符
&& || ! ^ | &
三元: ? =
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");
}
}
}