欢迎光临
我们一直在努力

java 基础数据类型-JSP教程,Java技巧及代码

建站超值云服务器,限时71元/月

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;                                  //cant fit double into a float 
                                             

赞(0)
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com 特别注意:本站所有转载文章言论不代表本站观点! 本站所提供的图片等素材,版权归原作者所有,如需使用,请与原作者联系。未经允许不得转载:IDC资讯中心 » java 基础数据类型-JSP教程,Java技巧及代码
分享到: 更多 (0)