总分:100
选择题得分:40
A.double me(int a,int b){int r; r = ab}
B.double me(a,b){return b;}
C.int me(int a,int b){return(a-b);}
D.int me(inta,b){return(a-b);}
正确答案是:C
A.float x(int a,int b){return(ab);}
B.int x(int a,int b){return ab;}
C.int x(int a,int b){return a * b;}
D.int x(int a,int b){return 1.2 *(a + b);}
正确答案是:D
A.int
B.float
C.double
D.byte
正确答案是:C
A.static
B.final
C.super
D.sub
正确答案是:D
A.–a
B.Test
C.class
D.#ABC
正确答案是:B
- 6.下列语句序列执行后,c的值是()int a = 3,b = 4,c = 0; ((a )<( - b)) c;
A.0
B.1
C.2
D.3
正确答案是:A
A.float f [] = new {2.4f,3.5f,5.7f,7.9f};
B.int a [] = {1,2,3,4,5}
C.double [] d = new double [10];
D.int [] a2;
正确答案是:A
- 8.下面()是Java数据类型中的int类型的取值范围。
A.$-2^ 7 $〜27−1
B.0 〜 216−1
C.$-2 ^ {15} $^ 〜 215−1
D.−231 〜231−1
正确答案是:D
- 9.在Java语言中,下面()类型可以表示整数基本数据类型。
A.single
B.byte
C.double
D.char
正确答案是:B
- 10.假设int a = -3; 则表达式a> 0?a:-a的结果是()
A.true
B.false
C.-3
D.3
正确答案是:D
编程题得分:60
输出所有的3位数字的质数得分:10/10
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
| import java.io.IOException; import java.util.Scanner;
public class Main { public static void main(String []args) throws IOException{ int size = 1000; int prime[] = new int[1000]; int pos=0; boolean flag; for (int i = 100; i < size; i++) { flag = false; for(int j=2; j <= Math.sqrt(i) ; j++) { if (i%j == 0){ flag = true; break; } } if ( !flag ) prime[pos++] = i; } int pf=0; for (int i = 0; i < prime.length; i++) { if (prime[i] != 0) { System.out.printf("%6d",prime[i]); pf ++; if (pf == 5) { pf = 0; System.out.println(); } } } } }
|
数列求和得分:10/10
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
| import java.io.IOException; import java.util.Scanner;
public class Main { public static void main(String []args) throws IOException{ Scanner s = new Scanner(System.in); double x = s.nextDouble(); int cnt = 1; double sum = 0; double single ; do { single = Math.pow(x, cnt)/fac(cnt); sum += Math.pow(-1, (cnt+1) % 2)*single; cnt ++; } while ( Math.abs(single) > 1e-4 ); System.out.printf("%.2f\n",sum); }
public static int fac (int a) { if (a == 0 || a == 1) return 1; return a*fac(a-1); } }
|
最大公约数得分:10/10
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
| import java.io.IOException; import java.util.Scanner;
public class Main { public static void main(String []args) throws IOException{ Scanner s = new Scanner(System.in); int a = s.nextInt(); int b = s.nextInt(); System.out.printf("%d",gcd(a,b)); } public static int gcd(int a,int b) { if ( b==0 ) return a; return gcd(b,a%b); } }
|
输出斐波那契数列的前10得分:10/10
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
| import java.io.IOException; import java.util.Scanner;
public class Main { public static void main(String []args) throws IOException{ int arr[] = new int[20]; int len = 10; arr[0] = 1; arr[1] = 1; for (int i = 2; i <len; i++) arr[i] = arr[i-2] + arr[i-1]; for (int i = 0; i <len; i++) { System.out.printf("%d",arr[i]); if( i != len - 1) System.out.print(" "); else System.out.println(); } } }
|