获取内容资料
Java编程

黑马程序员java笔记之四

public class T {public static void main(String args) {int max = Integer.MAX_VALUE;System.out.println(“整型的最大值为:”+max);       //整型的最大值为:2147483647System.out.println(“整型的最大值+1: “+(max+1));  //整型的最大值+1: -2147483648System.out.println(“整型的最大值+2: “+(max+2));  //整型的最大值+2: -2147483647}}如果现在要想避免数据的溢出,可以采用扩大数据类型的方式。int–>long

[java]  view plain copypublic class T {public static void main(String args) {int max = Integer.MAX_VALUE;System.out.println(“整型的最大值为:”+max);       //整型的最大值为:2147483647System.out.println(“整型的最大值+1: “+(max+1));  //整型的最大值+1: -2147483648System.out.println(“整型的最大值+2: “+(max+2));  //整型的最大值+2: -2147483647System.out.println(“整型的最大值+2: “+((long)max+2));  //2147483649}}字符类型

字符类型在内存中占有2个字节,可以用来保存英文字母等字符。计算机处理字符类型时,是把这些字符当成不同的整数来看待,

因此,严格说来,字符类型也算是整数类型的一种。

[java]  view plain copypublic class T {public static void main(String args) {char ch1 = ‘a’;     //字符是使用”括起来的数据char ch2 = 97;      //通过数字定义字符变量System.out.println(“ch1 = “+ch1);System.out.println(“ch2 = “+ch2);}

Similar Posts

发表评论

邮箱地址不会被公开。 必填项已用*标注