java的数据类型

在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);
 }
}
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值