正在學習java,你知道這些題的答案麼

1.Java語言是1995年發佈的,發佈該語言的公司是:D

A.Oracle

B.Borland

C.Microsoft

D.Sun

2.編譯和運行以下代碼的結果為:D

public class Hello{

public static void main(String a){

System.out.println("Hello");

}

}

A.編譯錯誤

B.運行輸出 "Hello"

C.編譯無錯,但運行時指示沒有定義構造方法

D.編譯無錯,但運行時指示沒有正確定義main方法

3.關於下列代碼說法正確的是:CD

public static void main(String[] arr) {

int first=100;

System.out.println(first);

System.out.println(second);

first = 123.456;

}

A.編譯正確

B.代碼System.out.println(first);行,編譯出錯

C.代碼System.out.println(second);行,編譯出錯

D.代碼first = 123.456;行,編譯出錯

4.下列代碼出錯的行是:C

1) public void modify() {

2) int i, j, k;

3) i = 100;

4) while ( i > 0 ) {

5) j = i * 2;

6) System.out.println (" The value of j is " + j );

7) k = k + 1;

8) i--;

9) }

10) }

A.4 B.6 C.7 D.8

5.下列程序編譯或運行的結果是:D

public static void main(String[] args) {

int num = 100;

for(int i=0;i<=100;i++) {

int num = 10;

}

System.out.println(num);

}

A.10 B.100 C.201 D.編譯出錯

A.double w=3.1415;

B.float z=6.74567;

C.boolean truth=true;

D.int i=128;

7.int類型整型變量在內存中的位數為:C

A.8 B.16 C.32 D.64

8.浮點數的字面量的類型是:C

A.int

B.float

C.double

D.long

9.char類型的整數範圍是:B

A.0 ... 32767

B.0 ... 65535

C.–256 ... 255

D.–32768 ... 32767

10.char,int,long,float,double的範圍由低到高的順序是:D

A.int-char-long-float-double

B.long-float-int-double-char

C.int-long-float-double-char

D.char-int-long-float-double

正在學習java,你知道這些題的答案麼

11.在Java中語句:37/10的運算結果為:A

A.3

B.3.70

C.3.7

D.3.0

12.編譯和運行以下代碼的結果為:B

public static void main(String args[]){

byte b=(byte)4096;

if(b==4096)

System.out.println("Equal");

else

System.out.println("Not Equal");

}

A.在第3行出現轉換丟失精度的編譯錯誤

B.輸出 "Not Equal"

C.輸出 "Equal"

D.在第4行出現編譯錯誤

13. 在Java語句中,運算符&&實現:B

A.邏輯或

B.邏輯與

C.邏輯非

D.邏輯相等

14.編譯運行以下程序後,關於輸出結果的說明正確的是:C

public static void main(String args[ ]){

int x=4;

System.out.println(“value is “+ ((x>4) ? 99.9 :9));

}

A.輸出結果為:value is 99.99

B.輸出結果為:value is 9

C.輸出結果為:value is 9.0

D.編譯錯誤

15.下列代碼的輸出結果是:A

int a=10;

1010 0010

1010|

0010|

System.out.println(a>>2);

A.2

B.4

C.40

D.42

16.~0010101語句的執行結果為:A

A.1101010

B.0010101

C.11111111

D.10001000

17.下面代碼的輸出結果是 B

public class Main {

public static void main(String[] args) {

int n1 = 1;

int n2 = 2;

n1 = n1 + n2;

n2 = n1 - n2;

n1 = n1 - n2;

System.out.println(n1 + "," + n2);

}

}

A.1,2

B.2,1

C.1,3

D.3,2

18.Java語言中字符串“學Java”所佔的內存空間是:C

A.6個字節

B.7個字節

C.10個字節

D.11個字節

19.下列代碼段的輸出結果是:D

public static void main(String[] args) {

int x = 5;

boolean b1 = true;

boolean b2 = false;

if ((x == 4) && !b2){

System.out.print("l ");

}

System.out.print("2 ");

if ((b2 = true) && b1)

System.out.print("3");

}

A.2

B.3

C.1 2

D.2 3

20.請看下列代碼:B

public void testIfA() {

if(true) {

System.out.println("True");

}else{

System.out.println("Not true");

}

}

public Boolean testIfB(String str) {

return boolean.valueOf(str);

}

調用testIfA方法,程序的結果是:

A.輸出Not true

B.輸出True

C.代碼 if (testIfB("True")) { 行,編譯錯誤

D.代碼 return Boolean.valueOf(str); 行,編譯錯誤

正在學習java,你知道這些題的答案麼

21.下列語句序列執行後,k 的值是。C

int i=10, j=18, k=30;

switch( j - i )

{

case 8 : k++;

case 9 : k+=2;

case 10: k+=3;

default : k/=j;

}

A.31

B.32

C.2

D.33

22. 以下由 for 語句構成的循環執行的次數是:B

for ( int i = 0; true ; i++) ;

A.執行3次

B.無限次

C.執行1次

D.一次也不執行

23.觀察以下程序段 :D

int i=1,j=10;

do{

if(i++>--j){ i= j=

continue; i= j=

}

} while(i<5);

執行完後, i 、 j 的值分別為:

A.i=6 j=5

B.i=5 j=5

C.i=6 j=4

D.i=5 j=6

正在學習java,你知道這些題的答案麼

24.下列代碼段編譯和運行的結果是:B

public static void main(String[] args) {

for (int i = 0; i <= 10; i++) {

if (i > 6)

break;

}

System.out.println(i);

}

A.輸出6

B.輸出7

C.輸出10

D.編譯錯誤

25.下面程序的輸出結果是:A

public static void main(String[] args) {

int d = 325;

int sum = 0;

while (d > 0) {

int n = d % 10; 5 2 3

sum += n; 5 7 10

d /= 10; 32 3 0

}

System.out.println(sum);

}

A.10

B.12

C.5

D.32

26.關於while和do-while循環,下列說法正確的是D

A.兩種循環除了格式不同外,功能完全相同

B.與do-while語句不同的是,while語句的循環至少執行一次

C.do-while語句首先計算終止條件,當條件滿足時,才去執行循環體中的語句

D.與while語句不同的是,do-while語句的循環至少執行一次

27.執行完以下代碼int[] x = new int[25];後,下列各項正確的是:A

A.x[24]為0

B.x[24]未定義

C.x[25]為0

D.x[0]為空

28.下列代碼編譯和運行的結果是:B

public static void main(String[] args) {

int[] x = { 1, 2, 3, 4, 5 };

x[3]

int[] y = x;

System.out.println(y[2]);

}

A.輸出2

B.輸出3

C.輸出4

D.編譯錯誤

29.下面代碼的輸出結果是C

public class Main {

public static void main(String[] args) {

int n = 100;

int m = 200;

System.out.println(f(n,m));

System.out.println(n);

}

public static int f(int m, int n) {

n = m+n;

return n;

}

}

A.300

300

B.100

100

C.300

100

D.100

300

30.下列代碼的輸出結果是:A

public static void main(String[] args) {

int[] arr = { 49, 81, 77, 1, 98,50, 0, 80, 77, 18 ,11,15};

Arrays.sort(arr);

int index = Arrays.binarySearch(arr, 80);

System.out.print(index+“ ”);

index = Arrays.binarySearch(arr, 90);

System.out.print(index);

}

A.9 -12

B.8 -11

C.8 -1

D.9 -1

31.實現對數組arry的冒泡升序排序,應填入的代碼是B

public static void bubbleSort(int[] arry) {

int len = arry.length;

for (int i = 1; i < len; i++) {

boolean asc = true;

if (asc) {

return

};

}

}

private static void swap(int[] arry, int i, int j) {

int temp = arry[i];

arry[i] = arry[j];

arry[j] = temp;

}

A.for (int j = len-1; j > i; j--) {

if (arry[j] < arry[j - 1]) {

swap(arry, j, j - 1);

asc = false;

}

}

B.for (int j = len - 1; j >= i; j--) {

if (arry[j] < arry[j - 1]) {

swap(arry, j, j - 1);

asc = false;

}

}

C.for (int j = len - 1; j >= i; j--) {

if (arry[j] > arry[j - 1]) {

swap(arry, j, j - 1);

asc = false;

}

}

D.for (int j = len - 1; j >= i; j--) {

if (arry[j] < arry[j - 1]) {

swap(arry, j, j - 1);

asc = true;

}

}

32.使用遞歸算法求10的階乘,下列選項正確的是:A

10*9*8******1

A. public static int method(int n) {

if (n < 1) {

return 0;

}

if (n == 1)

return 1;

else

return n * method(n - 1);

}

10*9*method(8)**3*2*1

B.public static int method(int n) {

if (n < 1) {

return 0;

}

if (n == 1)

return 1;

else

return n * (n - 1);

}

C.public static int method(int n) {

if (n < 1) {

return 0;

}

if (n> 1)

return 1;

else

return n * method(n - 1);

}

D.public static int method(int n) {

if (n < 1) {

return 0;

}

if (n > 1)

return 1;

else

return n * (n - 1);

}

33.Java語言可以跨平臺的原因是:B

A.Java面向對象

B.Java虛擬機

C.Java垃圾回收機制

D.Java編譯器

正在學習java,你知道這些題的答案麼

34.執行下列代碼後,哪個結論是正確的 String[] s=new String[10];AD

A. s[9] 為 null;

B. s[9] 為 "";

C. s[0] 為 未定義

D. s.length 為 10

35.請看下列表達式不正確的是:D

A.String name2 = "Jane Doe";

B.int $age=24;

C.Double _height = 123.5;

D.double ~temp = 37.5;

36.下列選項中能正確編譯的是:AB

A. public static void main(String[] args) {

int one=12;

System.out.println(one);

}

B.public static void main(String[] args) {

int one;

one=12;

System.out.println(one);

}

C. public static void main(String[] args) {

int one;

System.out.println(one);

}

D.public static void main(String[] args) {

int one;

int m=10;

if(m>0){

one=12;

}

System.out.println(one);

}

37.下列程序編譯或運行的結果是:C

public static void main(String[] args) {

for(int i=0;i<=100;i++) {

int num = 100;

}

for(int j=0;j<=100;j++) {

int num = 200;

}

int num = 300;

System.out.println(num);

}

A.輸出:100

B.輸出:200

C.輸出:300

D.編譯出錯

38.下列不屬於基本數據類型的是:B

A.整數類型

B.類

C.符點數類型

D.布爾類型

39.

1. public class test {

2. public static void main (String args[]) {

3. int i = 0xFFFFFFF1; 1111 1111 ---- 1111 0001

4. int j = ~i; 0000 0000 ---- 0000 1110

5.

6. }

7. }

十六進制:0x 0-9 a-f

八進制 0 0-7

程序運行到第 5 行時,j 的值為多少?( )D

A. –15

B. 0

C. 1

D. 14

E. 在第三行的錯誤導致編譯失敗

40.一下程序的輸出結果為:C

public static void main(String[] args){

int x = 1,y =1, z =1;

if(x--==1&&y++==1||z++==1){

System.out.println("x="+x+",y="+y+",z="+z)

}

}

A.x=0,y=1,z=1

B.x=0,y=2,z=2

C.x=0,y=2,z=1

D.x=1,y=2,z=1

41.語句System.out.println(1+2+"java"+3+4)輸出的結果是:A

A.3java34

B.12java34

C.3java7

D.12java7

42 下列代碼編譯和運行的結果是:A

public static void main(String[] args){

int[] someArray = new int[]{1,2,3}

for(int i=0;i<somearray.length>

System.out.println(someArray[i]);

}

//高級迭代for循環

for(int a:someArray){

System.out.println(a);

}

}

A. 1 2 3

B.代碼Object obj = new int[]{1,2,3};行,編譯錯誤

C.代碼int[] someArray = (int[])obj;行,編譯錯誤

D.代碼 for(int i:someArray)行,編譯錯誤

43.下列語句中相當於三元條件運算符ex1 ? ex2 : ex3的是:A

A.if (ex1) ex2 ; else ex3;

B.if (ex2) ex1 ; else ex3;

C.if (ex1) ex3 ; else ex2;

D.if (ex3) ex2 ; else ex1;

44.請看下列代碼:

public void go(){

String str = "";

for(int x = 0;x<3;x++){

for(int y = 0;y<2;y++){

if (x==1){

break;

}

if(x==2&&y ==1){

break;

}

}

}

System.out.println(str);

}

調用go方法,程序的輸出結果是C

A. 00

B. 0001

C. 000120

D. 00012021

45.下列代碼段中,循環執行的次數是:C

int x = 10;

do{

x--;

}while(x <= 5);

A.10次

B.0次

C.1次

D.超過10次

46:說說對變量的理解,用法規則

47:一個四位數,恰好等於去掉它的首位數字之後所剩的三位數的3倍,這個四位數是多少

//for(int number=1000;number<=3000;number++){

//if(number%1000*3==number){

//System.out.println(number);

//}

//}

48: 操場上100多人排隊,三人一組多1人,四人一組多2人,五人一組多3人,共多少人。

//for(int i=100;i<200;i++){

//if(i%3==1&&i%4==2&&i%5==3){

//System.out.println(i);

//}

//}

49:從1到500所有自然數中不含數字4的自然數共有多少個?

//int num=0;

//for(int i = 1;i<=500;i++){

//if(i/100!=4&&i/10%10!=4&&i%10!=4){

//num++;

//System.out.println(i);

//}

//}

//System.out.println(num);

50: 封裝兩個方法:第一個是隨機生成長度為n數組元素是0--100以內的方法,數組的長度由參數來決定,

第二個方法是把冒泡排序封裝成方法。參數是數組。

然後在main()方法裡 啟用控制檯,調用上面兩個方法,對數組進行排序。最後輸出排序後的數組

public class Demo2 {

//

//

//

//

// 註釋方法三種:

// 第一種:單行註釋 “//”

// 第二種:多行註釋: "/*" "*/"

// 第三種:文檔註釋:/** */

public static void main(String[] args) {

Scanner scan = new Scanner(System.in);

int n = scan.nextInt();

int[] arr = RandomArr(n);

arr =ButtleSort(arr);

System.out.println(Arrays.toString(arr));

}

/**

* 封裝冒泡排序

*

*/

public static int[] ButtleSort(int[] a){

for(int i = 0;i<a.length-1>

for(int j = 0;j<a.length-i-1>

if(a[j]>a[j+1]){

int number = a[j];

a[j] = a[j+1];

a[j+1] = number;

}

}

}

return a;

}

/*

* 隨機生成數組的方法

*/

public static int[] RandomArr(int n){

int[] array = new int[n];

for(int i=0;i

array[i]=(int)(Math.random()*101);

}

return array;

}

/<a.length-i-1>

/<a.length-1>

/<somearray.length>


分享到:


相關文章: