您的位置:首页 > 数据库 > MySQL

MySQL中Int类型、short和byte之间强制转换、String的replaceALL

2016-03-02 00:00 609 查看
1.mysql中int的最大填充长度
答案:11 位 最大填充长度指的是填充数据的位数

MySQL中int类型占用4个字节byte,每个byte占8位bit,每一个bit表示一位0或1.那么mysql中int类型能存储的的unsigned(无符号)类型的范围是0~2^32-1=4294967295 ;

signed(有符号)的范围是-2^31=-2147483648 ~ 2^31-1=2147483647;

能存储的数据位数是11位

2.经过强制类型转换以后,变量a, b的值分别为( )short a = 128; byte b = (byte) a;
答案:128 -128

a=0000000010000000,当进行强制转换时,byte是八位的,截取a的后八位,b=10000000;最高位是符号位,说明b是负数,在计算机中以补码表示,求其源码,先减1得到反码01111111,取反得到源码10000000,也就是-128.

3.以下代码将打印出
public static void main (String[] args) {
String classFile = "com. jd. ".replaceAll(".", "/") + "MyClass.class";
System.out.println(classFile);
}

答案:

/////////MyClass.class


JDK API 中关于String类的replaceAll方法

String replaceAll(String regex, String replacement)

Replaces each substring of this string that matches the given regular expression withe given replacement.

替换符合给定的正则表达式regex的子字符串为给定的replacement

第一个参数是正则表达式 正则表达式中'.' 默认情况下表示除了换行符之外的所有字符。 所以com. jd. 被替换为/////////

如果只想替换"." 正则表达式应该是"\.",在Java中应该是"\\.",因为Java中对"\"有特殊的要求。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: