以下哪个方法是正确的?
A: public static int Sum(int n, params int[] val){ int count = 0; foreach (int a in val){ count = count + a; } return count + n;}
B: public static int Sum(params int[] val, int n){ int count = 0; foreach (int a in val){ count = count + a; } return count + n;}
C: public static int Sum(params int[] v1, params int[] v2){ int c1 = 0, c2 = 0; foreach (int a in v1){ c1 = c1 + a; } foreach (int a in v2){ c2 = c2 + a; } return c1 + c2;}
D: public static int Sum(params int[] v, char ch){ int c = 0; foreach (int a in v){ c = c + a; } return c + ch;}
A: public static int Sum(int n, params int[] val){ int count = 0; foreach (int a in val){ count = count + a; } return count + n;}
B: public static int Sum(params int[] val, int n){ int count = 0; foreach (int a in val){ count = count + a; } return count + n;}
C: public static int Sum(params int[] v1, params int[] v2){ int c1 = 0, c2 = 0; foreach (int a in v1){ c1 = c1 + a; } foreach (int a in v2){ c2 = c2 + a; } return c1 + c2;}
D: public static int Sum(params int[] v, char ch){ int c = 0; foreach (int a in v){ c = c + a; } return c + ch;}
举一反三
- class Count { public int count; public Count(int c) { count = c; } public Count() { count = 1; }}public class Test { public static void increment(Count c, int times) { c.count++; times++; } public static void main(String args[]) { Count myCount = new Count(); int times = 0; for (int i = 0; i A: myCount.count=4 times=0 B: myCount.count=3 times=0 C: myCount.count=4 times=1 D: myCount.count=3 times=1
- class Count {public int count;public Count(int c) {count = c;}public Count(){count = 1;}}public class Test {public static void increment(Count c, int times) {c.count++;times++;}public static void main A: myCount.count=4 times=0 B: myCount.count=4 times=1 C: myCount.count=3 times=1 D: myCount.count=3 times=0
- 写出下列程序的输出结果 public class Test { public static void main(String[] args) { Count myCount = new Count(); int times = 0; for(int i=0;i<100;i++) increment(myCount , times); System.out.println(“count is” + myCount.count); System.out.println(“time is”+ times); } public static void increment(Count c , int times) { c.count++; times++; } } class Count { public int count; Count(int c) { count =c; } Count() { count =1; } }
- 下列程序中sumFun()的算法时间复杂度为 ( ) 。int sumFun(int n) { int count = 0; for (int i = 1; i < n; i = i * 2) for (int j = i; j > 0; j = j - 1) count = count + i + j; return count; } A: O(n) B: O(nlogn) C: O(n^2) D: O(logn logn)
- 代码中myCount.count的值为(A)?public class Test { public static void main(String[] args) { Count myCount = new Count(); int times = 0; for (int i=0; i<100; i++) increment(myCount, times); System.out.println("myCount.count = " + myCount.count); } public static void increment(Count c, int times) { c.count++; times++; }} class Count { int count; Count(int c) { count = c; } Count() { count = 1; }} A: 101 B: 100 C: 99 D: 98