EECE 521 Artificial Intelligence521人工智能专业_第1页
EECE 521 Artificial Intelligence521人工智能专业_第2页
EECE 521 Artificial Intelligence521人工智能专业_第3页
全文预览已结束

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

1、.CSCE 145: Test 1 Key, Spring 2013Questions 1 to 8 are worth 8 points each. Questions 9 to 12 are worth 9 points each.1. What would be the exact result of executing the following statements? int shoeSize = 9; String brand = “Manolo”; int total = shoeSize * 2; /9 System.out.println(“I want “ +brand +

2、“ shoes”); System.out.println(“What size?”); System.out.print(total +”, ”); System.out.println(shoeSize +“ for each foot. HaHa.”);I want Manolo shoesWhat size?18, 9 for each foot. HaHa.2. Suppose the class Dog has the boolean instance variable wagsTail and the setter method setWagsTail with one para

3、meter: a boolean. fido is an object in the class Dog. Write the statement that would cause the wagsTail instance variable for fido to be set to true.fido.setWagsTail(true);3. Assume that int x = 3, int y = 2, and int z = 6. What would be the value of variable b after the following statement is execu

4、ted? boolean b = (x < y) && (x * y / z > z) | (x + y <= z);/ F && F | T => F | T => T _true_4. What would be the value of variable c4 after the following statement is executed? int c4 = 2 * 5 + 4 3 * 2; _8_5. An apple grower has crates that hold 24 apples each. Assume

5、the grower picks n apples. Finish the following Java expression that would find how many apples would be in the last partially filled crate. For example, if he picked 51 apples, he could fill two crates and would have 3 apples left over. int leftOverApples = n % 24;6. What would be the value of vari

6、able total after the following statements are executed? int total = 4; total+; total = total * 5;_25_7. The following code uses a for-loop to compute the value of this sum: n=599n (n-1)int sum = 0;for (int n = 5; n <= 99; n+) sum = sum + n * (n 1);Convert it to an equivalent sum =

7、0;int n = 5;while (n <= 99) sum = sum + n * (n 1); n+;8. Write an int method summation() that has no parameters and returns the value of the summation in problem #12 above. You can use either a for-loop or a while-loop.public int summation() int sum = 0; for (int n = 5; n <= 99; n+) sum = sum

8、+ n * (n 1); return sum;9. What is the output of the following code segment? int i = 5; int j = 7; int k = 6; if (i > j) | (k < 5) System.out.println(“yes 1”); else System.out.println(“no 2”); if (i < j) && (k > 5) System.out.println(“yes 3”); else System.out.println(“no 4”);no 2

9、yes 310. Write the three Java expressions that are equivalent to the following three mathematical formulas: a2+b2 (t2 + 5 t 4) Math.sqrt(a*a + b*b) * (t*t + 5*t 4)(t-5)(t+8)/(2d+e) (t 5) * (t + 8) / (2 * d + e)-b+b2-4ac2a (-b + Math.sqrt(b*b 4*a*c) / (2*a)11. What is the output of the following code

10、 segment? String player1 = “rock”; String player2 = “paper”; if (player1.equals(player2) System.out.println(“Tie!”); else if (player1.equals(“rock”) if (player2.equals(“paper”) System.out.println(“Player 1 loses”); else System.out.println(“Player 1 wins”); else if (player1.equals(“paper”) if (player

11、2.equals(“rock”) System.out.println(“Player 1 wins”); else System.out.println(“Player 1 loses”); else /player1 s if (player2.equals(“rock”) System.out.println(“Player 1 loses”); else System.out.println(“Player 1 wins”); System.out.println(“Player 1 quits”);Player 1 losesPlayer 1 quits16512. Given th

12、e following definition for the classes Room and House, write a method in the House class called getSquareFootage that returns the total square footage of all three rooms in an instance of a House. public class Room private String type; / a variable for storing the type of a / Room, such as “kitchen,” or “bedroom” private int length; / the length of the Room in feet private int width; / the width of the Room in feet /Assume there are getters and setters for the 3 instance /variables above, such as getWidth() and getLength() public class House private Room br1; / bedroom #1 private

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论