开学了,这学期学习java课程,我会把课堂上和自学的内容总结并记录下来,加深记忆,同时帮助有需要的人。
1.自增和自减运算符
public class zizengzijian {
public static void main(String[] args) {
// TODO 自动生成的方法存根
int n1=5,n2=8;
System.out.println("n1++:"+(n1++));
System.out.println("n2--:"+(n2--));
System.out.println("++n1:"+(++n1));
System.out.println("--n2:"+(--n2));
}
}
------------------------------
n1++:5
n2--:8
++n1:7
--n2:6
2.比较运算符
public class test {
public static void main(String[] args) {
// TODO 自动生成的方法存根
int n1=5;
int n2=6;
/*依次将n1与n2比较结果输出*/
System.out.println("n1>n2的返回值为:"+(n1>n2));
System.out.println("n1<n2的返回值为:"+(n1<n2));
System.out.println("n1==n2的返回值为:"+(n1==n2));
System.out.println("n1!=n2的返回值为:"+(n1!=n2));
System.out.println("n1>=n2的返回值为:"+(n1>=n2));
System.out.println("n1<=n2的返回值为:"+(n1<=n2));
}
}
------------------------------
n1>n2的返回值为:false
n1<n2的返回值为:true
n1==n2的返回值为:false
n1!=n2的返回值为:true
n1>=n2的返回值为:false
n1<=n2的返回值为:true
3.逻辑运算符
public class test {
public static void main(String[] args) {
// TODO 自动生成的方法存根
int n1=21;
int n2=30;
/*声明boolean型变量,保存运算符的返回值*/
boolean result1=((n1>25)&&(n2<35));
boolean result2=((n1>25)||(n2<35));
System.out.println(result1);
System.out.println(result2);
}
}
------------------------------
false
true
4.三元运算符
条件式?值1:值2
public class test {
public static void main(String[] args) {
// TODO 自动生成的方法存根
int n1=21;
int n2=30;
boolean result=n1<n2?true:false;
System.out.println(result);
}
}
------------------------------
true
相当于
public class test {
public static void main(String[] args) {
// TODO 自动生成的方法存根
int n1=21;
int n2=30;
boolean result;
if (n1<n2)
result=true;
else
result=false;
System.out.println(result);
}
}
-----------------------------
true
5.数据类型转换
public class test {
public static void main(String[] args) {
// TODO 自动生成的方法存根
int n1=(int)3.25;
long n2=(long)456.6F;
double n3=(double)14;
System.out.println(n1);
System.out.println(n2);
System.out.println(n3);
}
}
-----------------------------
3
456
14.0
6.注释
单行注释://注释内容
多行注释:/*注释内容*/
文档注释:/**注释内容*/