在java中没有64位平台和32位平台之分,一般都数据类型的字节数都是确定的
整形
int 四个字节 整形
long 八个字节 长整形
public class Start {
public static void main(String args[]) {
int a = 10;
System.out.println("a = " +a);
long b = 20L;//一般长整型数字后面加一个大写L,用来区别于整形
System.out.println("b = " +b);
}
}
浮点型
double 8个字节 双精度浮点数
float 4个字节 单精度浮点数
public class Start {
public static void main(String args[]) {
double a = 1.0;
double b = 2.0;
System.out.println("a/b = " +a/b);
int c = 1;
int d = 2;
System.out.println("c/d = " +c/d);
float e = 1.0f;
float f = 2.0f;//同样用作区分
System.out.println("e/f = " +e/f);
}
}
字符型变量
char 两个字节
与C语言中不同的是用的是unicode字符集
public class Start {
public static void main(String args[]) {
char a = '李';
System.out.println(a);
char b = 'p';
System.out.println(b);
}
}
字节型变量
byte 一个字节(-128---->127)
无论是那个变量,给其赋值时不能超过其表达的范围。
public class Start {
public static void main(String args[]) {
byte a = 127;
System.out.println(a);
int b = Integer.MAX_VALUE + 1;
System.out.println(b);//体会一下
System.out.println(Integer.MAX_VALUE);
System.out.println(Integer.MAX_VALUE + 1);
}
}
短整型
short 2个字节 (-32768---->32767)
public class start {
public static void main(String[] args) {
short s = 32767;
System.out.println(s);
System.out.println(Short.MAX_VALUE);
}
}
布尔类型
boolean 只有两个取值 一个为true 一个为false
public class Start {
public static void main(String args[]) {
boolean value = true;
System.out.println(value);
}
}
字符串类型
string
在C语言中是没有字符串类型的。
public class Start {
public static void main(String args[]) {
String s = "abcdef";
System.out.println(s);
int a = 10;
System.out.println("a = " +a);
int b = 20;
System.out.println(a + b);
System.out.println("a+b = " +a+b);
System.out.println("a+b = " +(a+b));
System.out.println("a+b = " +a+ " " +b);
double c = 12.6;
System.out.println("mmmmm=" +c);
}
}

被折叠的 条评论
为什么被折叠?



