定义 java 基本数据类型

 1 package debug;
 2 
 3 class Demo {
 4     /*
 5      * 定义八种基本数据类型,如下
 6      */
 7     
 8     public static void main(String[] args) {
 9         //define  char type
10         char a = '1';     //字符类型用单引号
11         System.out.println(a);
12         
13         //define string type
14         String text = "Hello world";  //字符串类型用双引号
15         System.out.println(text);
16         
17         //define float type
18         float f = 1.03F;   //单精度浮点类型后面必须要带上F或者f,默认用F
19         System.out.println(f);
20         
21         //define double type
22         double d = 1.345;  //浮点类型默认为双精度,所以如果定义的是doule类型,后面就不需要再带上F
23         System.out.println(d);
24         
25         //define short type
26         short s = 100;
27         System.out.println(s);
28         
29         //define int type
30         int i = 101;
31         System.out.println(i);
32         
33         //define long type
34         long l = 10000000000L; //定义长整型后面必须要带上L或者l,默认用L
35         System.out.println(l);
36         
37         //define byte type
38         byte a1 = 102;
39         System.out.println(a1);
40         
41         //define boolean
42         boolean b = false;
43         System.out.println(b);
44         
45         
46     }
47     
48 }

 输出如下:

1 1
2 Hello world
3 1.03
4 1.345
5 100
6 101
7 10000000000
8 102
9 false

 

转载于:https://www.cnblogs.com/aziji/p/9987846.html

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值