• 软件测试技术
  • 软件测试博客
  • 软件测试视频
  • 开源软件测试技术
  • 软件测试论坛
  • 软件测试沙龙
  • 软件测试资料下载
  • 软件测试杂志
  • 软件测试人才招聘
    暂时没有公告

字号: 小 中 大 | 推荐给好友 上一篇 | 下一篇

java 基础数据类型

发布: 2007-7-01 18:47 | 作者: admin | 来源: | 查看: 48次 | 进入软件测试论坛讨论

领测软件测试网

1.简单数据类型
逻辑类型  boolean
文本类型  char,String(特殊类型)
整数类型  byte,short,int,long
浮点类型  double,float

boolean  两个值:true and false
char  16位无符号(不分正负的)Unicode字符 必须包含在单引号内(@#@#)
       eg:@#\t@# 表示一个制表符
            @#\u????@# 表示一个特殊的Unicode字符 ????应严格按照4个16进制数进行替换.
String  不是一个简单的数据类型 而是一个类(class) 它被用来表示字符序列.字符本身符合Unicode标准
         且上述char类型的反斜线符号适用于String.
         与c and c++ 不同,String不能用@#\o@#作为结束.(本来要写@#\零@#的,可是它就是不显示,没招儿了,就用o来代替吧~~)
byte short int long
         在数据后面直接跟一个字母"L".L表示这是一个long型数值.在Java编程语言中L无论是大写还是小写都同样有效,但由于小写l与数字1容易混淆,因而,使用小写不是一个明智的选择.
                                           整型数据的长度和数值范围
   ----------------------------------------------------------------------------------------------------------------------
        长度                                    数据类型                                  数值范围
   ----------------------------------------------------------------------------------------------------------------------
        8 bits                                     byte                                   -2(7)~2(7)-1
        16 bits                                   short                                   -2(15)~2(15)-1
        32 bits                                   int                                      -2(31)~2(31)-1
        64 bits                                   long                                    -2(63)~2(63)-1
   ---------------------------------------------------------------------------------------------------------------------
float double  
          数值包含小数点或指数,或者在数字后面带有字母F or f(float), D or d(double)
                                           浮点型数据的长度和数值范围
   ----------------------------------------------------------------------------------------------------------------------
        长度                                    数据类型                                  数值范围
   ----------------------------------------------------------------------------------------------------------------------
        32 bits                                   float                              1.401e-45~3.402e+38
        64 bits                                   long                              4.94e-324~1.79e+308d
   ----------------------------------------------------------------------------------------------------------------------

2.简单数据类型变量的声明和赋值
public class Assign{
  public static void main(String[] args){
     int x,y;                                          //declare int variables
     float z=3.414f;                               //declare and assign float variable
     double w=3.1415;                          //declare and assign double variable
     boolean truth=true;                        //declare and assign boolean variable
     char c;                                           //declare character variable
     String str;                                       //declare String variable
     String str1="bye";                            //declare and assign String variable
  c=@#A@#;                                                //assign value to char variable
  str="Hi out there!";                             //assign value to String variable
  x=6;
  y=1000;                                            //assign values to int variable
  ...
  }
}

下面是一些非法赋值的语句:
y=3.1415926;                               //is not an int.Requires casting and decimal will be truncated
w=175,000;                                 //the comma symbol(,)cannot appear
truth=1;                                      //a common mistake made by ex- c/c++ programmers
z=3.14156;                                  //can@#t fit double into a Float 
                                             

延伸阅读

文章来源于领测软件测试网 https://www.ltesting.net/


关于领测软件测试网 | 领测软件测试网合作伙伴 | 广告服务 | 投稿指南 | 联系我们 | 网站地图 | 友情链接
版权所有(C) 2003-2010 TestAge(领测软件测试网)|领测国际科技(北京)有限公司|软件测试工程师培训网 All Rights Reserved
北京市海淀区中关村南大街9号北京理工科技大厦1402室 京ICP备10010545号-5
技术支持和业务联系:[email protected] 电话:010-51297073

软件测试 | 领测国际 | ISTQB | ISTQB官网 | TMMi | TMMi认证 | 国际软件测试工程师认证 | 领测软件测试网