一、基础语言:
1 基本数据类型:(一字节等于八位)
1.1 整数型:byte、short、int、long
1.2 浮点型:float、double
1.3 字符型:char
1.4 布尔型:boolean(一个字节、一位)
package cz.oneday.csdn;
public class number {
public static void main(String[] args) {
//整型
byte b=19-5;
short s=200/10;
int i=10;
long l=11111111L*11111111111111111l;
System.out.println(b);
System.out.println(s);
System.out.println(i);
System.out.println(l);
//浮点型
float f=33.33f;
double d=123456.1234;
System.out.println(f);
System.out.println(d);
//字符型
char ch='a';
char ch1=97;
System.out.println(ch);
System.out.println(ch1);
//布尔值
boolean b1=true;
boolean b2=false;
System.out.println(b1);
System.out.println(b2);
}
}
2 数据类型转化:
2.1 隐式转化:byte->short->int->long->float->double
2.2 显示转化:double->int、float->long、double->char
package cz.oneday.csdn;
public class Change {
public static void main(String[] args) {
//隐式转换
byte b=127;
int i=360;
float f=360.36f;
char c='a';
double d=45.1234;
System.out.println("byte+float="+(b+f));
System.out.println("byte+int="+(b+i));
System.out.println("byte+char="+(b+c));
System.out.println("double+char="+(d+c));
//显示转化
int a=(int)45.23;
long b1=(long)123.2f;
char c1=(char)97.12;
System.out.println("double->int\t"+a);
System.out.println("float->long \t"+b1);
System.out.println("double->char\t"+c1);
}
}
3.运算符:(&&||)
3.1 a++,++b
3.2 a1–,–b1
3.3 &&与||
package cz.oneday.csdn;
public class chaaar {
public static void main(String[] args) {
int s,s1,s2,s3;
int a=1,a1=1,b=1,b1=1;
//a++
System.out.println(".................a++.....................");
a++;
System.out.println("a="+a);
s=a++;
System.out.println("a="+a+"\ts="+s);
//++b
System.out.println(".................++b.....................");
++b;
System.out.println("b="+b);
s1=++b;
System.out.println("b="+b+"\ts1="+s1);
//a1--
System.out.println(".................a1--.....................");
a1++;
System.out.println("a1="+a1);
s2=a++;
System.out.println("a1="+a1+"\ts2="+s2);
//--b1
System.out.println("................--b1......................");
++b1;
System.out.println("b1="+b1);
s3=++b1;
System.out.println("b1="+b1+"\ts3="+s3);
System.out.println("...................&&和||..................");
int x=3,y=6;
boolean re=((x>y)&&(x!=y));
boolean re1=((x>y)||(x!=y));
System.out.println("....&&"+re);
System.out.println("。。。||"+re1);
}
}