Unit 1 Primitive Types Practice Test Question 1 What Data Type Would

Unit 1 Primitive Types Practice Test Question 1 What Data Type Would

AP Computer Science A - Unit 1 Primitive Types Practice Test Question 1 What data type would be best used to record the number of people at a party? A. String B. Real C. Boolean D. Integer Question 2 What is the output for this statement? System.out.print("Good "); System.out.print("Morning!"); A. GoodMorning! B. Good Morning! C. Good Morning! D. Good.Morning! Question 3 What data type would be best used to record an email address? A. Real B. Integer C. String D. Character Question 4 Consider the following code: int a = 14; int b = -15; int c = 22; int d = 11; if(a > 12 && b < -14 && c < d) { System.out.println("YAY!!!!"); } else if (d - 20 < b) { System.out.println("GO DO MORE PROGRAMMING!"); } else if(a + 12 >= c) { System.out.println("This is vexing......"); } else { System.out.println("This is very fun!"); }} What is the output for the code above? A. This is very fun! B. This is vexing...... C. YAY!!!! D. GO DO MORE PROGRAMMING! Question 5 What are the types of operators? A. Relational and assignment B. Arithmetic and logical C. Conditional and increment or decrement D. All of the above Question 6 What is the output for this statement? System.out.println("Good "); System.out.println("Morning!"); A. Good Morning! B. Good. Morning! C. Good.Morning! D. Good Morning! Question 7 Consider the code below: int a = 24, b = 17, c = 5, d = 7; b = b % d + a / b; a %= b; a -= 12; What is the value of a at the end of the code above? A. -8 B. -12 C. 8 D. 12 Question 8 Which of the following is a valid variable declaration in Java? A. int myInteger = 0; B. int 1myInteger = 0; C. int my Integer = 0; D. int int = 0; Question 9 Which of the following declares a String array of size i? (Presume Java syntax.) A. String[] s[i]; B. String s = new String[i]; C. String[] s = new String[i]; D. String s[] = new String[i]; Question 10 What are the ways to create string objects in Java? A. Wrapper classes and Pool constant B. New operator only C. String literal only D. String literal and new operator Question 11 What is the difference between double and int? A. Int can hold positive numbers only and double can hold all numbers. B. Int can hold real numbers and double can only hold imaginary numbers. C. Int can only hold integer values, double can hold any number including decimals. D. Int can hold all values whereas double can only store two-digit values. Question 12 What data type would be the answer to the expression x < 5? A. Character B. Boolean C. String D. Real Question 13 What is the difference between system.out.println() and system.out.print()? A. They have no difference B. System.out.println() is only for beginners and system.out.print() is for experts C. System.out.print() throws the cursor to the next line after printing the desired result. D. System.out.println() throws the cursor to the next line after printing the desired result. Question 14 int x=2; double y=2.1; float z=3.0; int c=(x*y) + z; What is the value of c A. 7 B. 7.2 C. 6.3 D. 6 Question 15 Consider the following code: int i = 55, j = 3; System.out.println((i / j + 3) / 5); What is the output for the code above? A. 1.2 B. 4 C. 4.26667 D. 4.26666666667 Question 16 int i = 100; double d = 4.55, d2 = 3.75; int j = (int)(d * 100 + d2); What is the value of j at the end of the code's execution? A. 411 B. 458 C. 403 D. 399 Question 17 Consider the code below: int[] vals = {841,-14,1,41,49,149,14,148,14}; boolean[] bools = new boolean[vals.length]; for(int i = 0; i < vals.length; i++) { bools[i] = vals[i] > 20 && vals[i] % 2 == 0; } for(int i = 0; i < bools.length; i++) { if(bools[i]) { System.out.println(vals[i]); } } What is the output of the code above? A. false false false false false true false B. false true false true false true false C. 148 D. 841 41 49 149 Question 18 Expressions cannot contain variables of different data types. True or false? A. True B. Sometimes true C. Sometimes false D. False Question 19 string str = "Hello" char newvar = str[4]; What is the value of newvar? A. ‘l’ B. ‘H’ C. ‘o’ D. “ ” Answer Key 1. D 2. C 3. C 4. B 5. D 6. A 7. B 8. A 9. C 10.D 11.C 12.B 13.D 14.A 15.B 16.B 17.C 18.D 19.C.

View Full Text

Details

  • File Type
    pdf
  • Upload Time
    -
  • Content Languages
    English
  • Upload User
    Anonymous/Not logged-in
  • File Pages
    6 Page
  • File Size
    -

Download

Channel Download Status
Express Download Enable

Copyright

We respect the copyrights and intellectual property rights of all users. All uploaded documents are either original works of the uploader or authorized works of the rightful owners.

  • Not to be reproduced or distributed without explicit permission.
  • Not used for commercial purposes outside of approved use cases.
  • Not used to infringe on the rights of the original creators.
  • If you believe any content infringes your copyright, please contact us immediately.

Support

For help with questions, suggestions, or problems, please contact us