银符考试题库B12
现在是:
试卷总分:100.0
您的得分:
考试时间为:
点击“开始答卷”进行答题
System.out.println(Byte.MAX_VALUE); System.out.println(Byte.MIN_VALUE); |
byte b=(byte)129; |
基本类型占用内存情况 | ||||||||||||||||||||||||||||||
基本类型 | 大小 | 最小值 | 最大值 | |||||||||||||||||||||||||||
boolean | — | — | — | |||||||||||||||||||||||||||
char | 16bit | Unicode 0 | Unicode 2^16-1 | |||||||||||||||||||||||||||
byte | 8bit | -128 | +127 | |||||||||||||||||||||||||||
short | 16bit | -2^15 | +2^15-1 | |||||||||||||||||||||||||||
int | 32bit | -2^31 | +2^31-1 | |||||||||||||||||||||||||||
long | 64bit | -2^63 | +2^63-1 | |||||||||||||||||||||||||||
float | 32bit | IEEE 754 | IEEE 754 | |||||||||||||||||||||||||||
double | 64bit | IEEE 754 | IEEE 754 | |||||||||||||||||||||||||||
void | — | — | — |
public class Test { public static void main(String args[]) { int i; i=6; System.out.print(i); System.out.print(i++); System.out.print(i); } } |
a=0; c=0; do{ --c; a=a-1; }while(a>0); |
long temp=(int)3.9; temp%=2; |
自动转换条件 | |||||||||||||||||||||||||||||||||||
操作数1类型 | 操作数2类型 | 转换后的类型 | |||||||||||||||||||||||||||||||||
long | byte short char int | long | |||||||||||||||||||||||||||||||||
int | byte short char | int | |||||||||||||||||||||||||||||||||
float | byte short int char long | float | |||||||||||||||||||||||||||||||||
double | byte short int long char float | double |
强制转换条件 | |||||||||||||||||||||||
原操作数类型 | 转换后操作数类型 | ||||||||||||||||||||||
byte | char | ||||||||||||||||||||||
char | byte | ||||||||||||||||||||||
short | byte char | ||||||||||||||||||||||
int | byte short char | ||||||||||||||||||||||
long | byte short char | ||||||||||||||||||||||
float | byte short char int long | ||||||||||||||||||||||
Double | byte short char int long |
int n=999; n--; ++n; System.out.println(n++); |
public class Test { public static void main(String args[]) { int i=Integer.MAX_VALUE; if(i>i+1) { System.out.println("存在"); } } } |
存在 |
public class Test { public int test() { int i; i++; return i; } public static void main(String args[]) { Test test=new Test(); test.test(); System.out.println(new Test().test()); } } |
public class Test { static int i; public int test() { i++; return i; } public static void main(String args[]) { Test test=new Test(); test.test(); System.out.println(new Test().test()); } } |
Integer i=new Integer(4); Long l=new Long(4); Double d=new Double(4.0); |
int x=8,y=2,z; x=++x*y; z==x/y++; |
public class Test{ public static void main(String[] args){ System.out.println(1.0/0.0); System.out.println(Double.islnfinite(1.0/0.0)); System.out.println(Double.NEGATIVE_INFINITY); System.out.println(Double.POSITIVE_INFINITY); } } |
Infinity true -Infinity Infinity |
public class Test { public static void main(String argv[]) { int[] arr=new int[5]; System.out.println(arr[5]); } } |
public class Person { static int arr[]=new int[10]; public static void main(String a[]) { System.out.println(arr[1]); } } |
String s="xbcde"; System.out.priutln(s.charA.t(4)); |
public class Test { public void change(String str,char ch[]) { str="test ok"; ch[0]='g'; } public static void main(String args[]) { String str=new String("good"); char[]ch={'a','b','c'}; Test ex=new Test(); ex.change(str,ch); System.out.print(str+"and"); System.out.print(ch); } } |
public class Test { public static void main(String[] args) { String s="Hello"; s+="world"; System.out.println(s); } } |
Hello world |
public class Test{ public static void main(String[] args){ System.out.println(Math.min(Integer.MIN_VALUE,0)); System.out.println(Math.rain(Double.MIN_VALUE,0.0d)); } } |
class Test{ class Dog{ private String name; private int age; private int step; Dog(String s,int a){ name=s; age=a; step=0; } public void run(Dog fast){ fast.step++;} } public static void main (String args[]){ Test a=new Test(); Dog d=a.new Dog("Tom",3); d.step=25; d.run(d); System.out.println(d.step); } } |
int s=0; for(int i=0;i<arr.length;i++) if (i%2==0) { s+=arr[i]; } System.out.println(s); |
String str1="hello world"; String str2="hello"+new String("world"); System.out.println(str1==str2); |
class Test { public static void main(String[] args) { short a=1; short c=2; int b=2; a+=b;//运算结果隐式转换为short System.out.println("a="+a); //a=a+c;//编译错误,因为a+c结果为int类型,不能隐式转为int a=(short)(a+c); System.out.println("a="+a); } } |
a=3 a=5 |
public class Test { public static void main(String[] args) { Test t=new Test(); int i=0; t.increase(i); i=i++; System.out.println(i); } void increase(int i) { i++; } } |
public class Test { public static void testString() { String s="Hello"; String s1="world"; long start=System.currentTimeMillis(); for(int i=0;i<10000;i++) { s+=s1; } long end=System.currentTimeMillis(); long runTime=(end-start); System.out.println("testString:"+runTime); } public static void testStringBuffer() { StringBuffer s=new StringBuffer("Hello"); String s1="world"; long start=System.currentTimeMillis(); for(int i=0;i<10000;i++) { s.append(s1); } long end=System.currentTimeMillis(); long runTime=(end-start); System.out.primln("testStringBuffer:"+runTime); } public static void main(String[] args) { testStfing(); testStringBuffer(); } } |
testString:1760 testStringBuffer:3 |