1、Exam11301Ch123Name:_Covers Chapters 1-3 50 minsCSCI 1301 Introduction to ProgrammingArmstrong Atlantic State UniversityInstructor: Y. Daniel LiangPart I. (10 pts) Show the printout of the following code: (write the printout next to each println statement if the println statement is executed in the p
2、rogram).public class Test public static void main(String args) System.out.println(int)(Math.random(); System.out.println(Math.pow(2, 3); System.out.println(34 % 7);System.out.println(3 + 4 * 2 2 * 9); int number = 4; if (number % 3 = 0) System.out.println(3 * number);System.out.println(4 * number);i
3、nt x = 943;System.out.println(x / 100); System.out.println(x % 100);System.out.println(x + is + (x % 2 = 0) ? even : odd); int y = -1; y+;System.out.println(y); Part II: 1. (10 pts) Write a program that prompts the user to enter the exchange rate from currency US dollars to Chinese RMB. Prompt the u
4、ser to enter 0 to convert from US dollars to Chinese RMB and 1 vice versa. Prompt the user to enter the amount in US dollars or Chinese RMB to convert it to Chinese RMB or US dollars, respectively. Here are the sample runs:Enter the exchange rate from dollars to RMB: 6.81Enter 0 to convert dollars t
5、o RMB and 1 vice versa: 0Enter the dollar amount: 100$100.0 is 681.0 YuanEnter the exchange rate from dollars to RMB: 6.81Enter 0 to convert dollars to RMB and 1 vice versa: 1Enter the RMB amount: 1000010000.0 Yuan is $1468.432. (10 pts) Write a program that prompts the user to enter an integer. If
6、the number is a multiple of 5, print HiFive. If the number is divisible by 2 or 3, print Georgia. Here are the sample runs:Enter an integer: 6GeorgiaEnter an integer: 15HiFive GeorgiaEnter an integer: 25HiFive Part III: Multiple Choice Questions: (1 pts each)(Please circle your answers on paper firs
7、t. After you finish the test, enter your choices online to LiveLab. Log in and click Take Instructor Assigned Quiz. Choose Quiz1. You have 5 minutes to enter and submit the answers.)1. The expression (int)(76.0252175 * 100) / 100 evaluates to _.a. 76b. 76.0252175c. 76.03d. 76.02#2. What is y after t
8、he following switch statement? int x = 0; int y = 0; switch (x + 1) case 0: y = 0; case 1: y = 1; default: y = -1 a. 2b. 1c. 0d. -1#3. Assume x is 0. What is the output of the following statement?if (x 0) System.out.print(x is greater than 0);else if (x 3) ? 2 : 3;a. 5b. 2c. 3d. 4#7. Analyze the fol
9、lowing code. int x = 0; if (x 0); System.out.println(x); a. The value of variable x is always printed.b. The symbol x is always printed twice.c. The symbol x is always printed.d. Nothing is printed because x 0 is false.#8. To declare a constant MAX_LENGTH inside a method with value 99.98, you writea
10、. final double MAX_LENGTH = 99.98;b. double MAX_LENGTH = 99.98;c. final MAX_LENGTH = 99.98;d. final float MAX_LENGTH = 99.98;#9. Which of the following is a constant, according to Java naming conventions?a. readb. MAX_VALUEc. ReadIntd. Test#10. What is y after the following switch statement is execu
11、ted?x = 3;switch (x + 3) case 6: y = 0; case 7: y = 1; default: y += 1;a. 1b. 4c. 3d. 2e. 0#11. Which of the following code displays the area of a circle if the radius is positive.a. if (radius = 0) System.out.println(radius * radius * 3.14159);d. if (radius 0) System.out.println(radius * radius * 3
12、.14159);Solution:Part I:08.06false16943943 is odd0Part II:1.import java.util.Scanner;public class Exercise3_31 public static void main(String args) Scanner input = new Scanner(System.in);System.out.print(Enter the exchange rate from dollars to RMB: ); double rate = input.nextDouble(); System.out.pri
13、nt(Enter 0 to convert dollars to RMB and 1 vice versa: ); int conversionType = input.nextInt(); if (conversionType = 0) System.out.print(Enter the dollar amount: ); double dollars = input.nextDouble(); double RMB = dollars * rate; System.out.println($ + dollars + is + RMB + Yuan); else System.out.pr
14、int(Enter the RMB amount: ); double RMB = input.nextDouble(); double dollars = RMB / rate; System.out.println(RMB + Yuan + is + $ + dollars); 2.import java.util.Scanner;public class Test public static void main(String args) Scanner input = new Scanner(System.in); System.out.println(Enter an integer:
15、 ); int number = input.nextInt(); if (number % 5 = 0) System.out.println(HiFive); if (number % 2 = 0 | number % 3 = 0) System.out.println(Georgia); Part III:1. The expression (int)(76.0252175 * 100) / 100 evaluates to _.a. 76b. 76.0252175c. 76.03d. 76.02Key:a#2. What is y after the following switch
16、statement? int x = 0; int y = 0; switch (x + 1) case 0: y = 0; case 1: y = 1; default: y = -1 a. 2b. 1c. 0d. -1Key:d#3. Assume x is 0. What is the output of the following statement?if (x 0) System.out.print(x is greater than 0);else if (x 3) ? 2 : 3;a. 5b. 2c. 3d. 4Key:c#7. Analyze the following cod
17、e. int x = 0; if (x 0); System.out.println(x); a. The value of variable x is always printed.b. The symbol x is always printed twice.c. The symbol x is always printed.d. Nothing is printed because x 0 is false.Key:c#8. To declare a constant MAX_LENGTH inside a method with value 99.98, you writea. fin
18、al double MAX_LENGTH = 99.98;b. double MAX_LENGTH = 99.98;c. final MAX_LENGTH = 99.98;d. final float MAX_LENGTH = 99.98;Key:a#9. Which of the following is a constant, according to Java naming conventions?a. readb. MAX_VALUEc. ReadIntd. TestKey:b#10. What is y after the following switch statement is
19、executed?x = 3;switch (x + 3) case 6: y = 0; case 7: y = 1; default: y += 1;a. 1b. 4c. 3d. 2e. 0Key:d#11. Which of the following code displays the area of a circle if the radius is positive.a. if (radius = 0) System.out.println(radius * radius * 3.14159);d. if (radius 0) System.out.println(radius * radius * 3.14159);Key:d
copyright@ 2008-2022 冰豆网网站版权所有
经营许可证编号:鄂ICP备2022015515号-1