加载中…
个人资料
  • 博客等级:
  • 博客积分:
  • 博客访问:
  • 关注人气:
  • 获赠金笔:0支
  • 赠出金笔:0支
  • 荣誉徽章:
正文 字体大小:

AP计算机科学A课程真题

(2018-06-05 14:38:31)
标签:

ap计算机

ap计算机科学a

课程

2015年真题

学习资料

Consider the following incomplete method, which is intended to return the number of integers that evenly divide the integer inputVal. Assume that inputVal is greater than 0.

  1. public static int numDivisors(int inputVal)
  2. {
  3. int count = 0;
  4. for (int k = 1; k <=inputVal; k++)
  5. {
  6. if ( )
  7. {
  8. count++;
  9. }
  10. }
  11. return count;
  12. }

Which of the following can be used to replace so that numDivisors will work as intended?

 
 
 
 
 

 

Consider the following code segment.

  1. for (int r = 3; r > 0; r--)
  2. {
  3. int c;
  4. for (c = 1; c < r; c++)
  5. {
  6. System.out.print("-");
  7. }
  8. for (c = r; c <= 3; c++)
  9. {
  10. System.out.print("*");
  11. }
  12. System.out.println();
  13. }

What is printed as a result of executing the code segment?

 
 
 
 
 

 

Consider the following two classes.

  1. public class A
  2. {
  3. public void show()
  4. {
  5. System.out.print("A");
  6. }
  7. }
  8. public class B extends A
  9. {
  10. public void show()
  11. {
  12. System.out.print("B");
  13. }
  14. }

What is printed as a result of executing the following code segment?

  1. A obj = new B();
  2. obj.show();
 
 
 
 
 

Consider the following method, biggest, which is intended to return the greatest of three integers. It does not always work as intended.

  1. public static int biggest(int a, int b, int c)
  2. {
  3. if ((a > b) && (a > c))
  4. {
  5. return a;
  6. }
  7. else if ((b > a) && (b > c))
  8. {
  9. return b;
  10. }
  11. else
  12. {
  13. return c;
  14. }
  15. }

Which of the following best describes the error in the method?

 
 
 
 
 

Consider the following method.

  1. public static void showMe(int arg)
  2. {
  3. if (arg <</span> 10)
  4. {
  5. showMe(arg+1);
  6. }
  7. else
  8. {
  9. System.out.print(arg + " ");
  10. }
  11. }

What will be printed as a result of the call showMe(0)?

 
 
 
 
 


Consider the following sort method. This method correctly sorts the elements of array datainto increasing order.

  1. public static void sort(int[] data)
  2. {
  3. for ( int j = 0; j < data.length - 1; j++)
  4. {
  5. int m = j;
  6. for (int k = j + 1; k < data.length; k++)
  7. {
  8. if (data[k] < data [m])
  9. {
  10. m = k;
  11. }
  12. }
  13. int temp = data[m];
  14. data[m] = data[j];
  15. data[j] = temp;
  16. }


AP计算机 AP微积分 ALevel计算机 IGCSE计算机 辅导
支持远程现场互动教学 wechat:APFlying

0

阅读 收藏 喜欢 打印举报/Report
  

新浪BLOG意见反馈留言板 欢迎批评指正

新浪简介 | About Sina | 广告服务 | 联系我们 | 招聘信息 | 网站律师 | SINA English | 产品答疑

新浪公司 版权所有