Introduction to Computer Programming Chp. 2 Study Guide

Terri FLetcher
Note by Terri FLetcher, updated more than 1 year ago
20
0
0

Description

Note on Introduction to Computer Programming Chp. 2 Study Guide, created by Terri FLetcher on 02/10/2016.
Tags No tags specified

Resource summary

Page 1

Introduction to Computer Programming Chp. 2 Study Guide1. Suppose a Scanner object is created as follows:Scanner input = new Scanner(System.in);What method do you use to read an int value? A. input.nextInt(); B. input.nextInteger(); C. input.int(); D. input.integer();2. The following code fragment reads in two numbers:Scanner input = new Scanner(System.in);int i = input.nextInt();double d = input.nextDouble();What are the correct ways to enter these two numbers? A. Enter an integer, a space, a double value, and then the Enter key. B. Enter an integer, two spaces, a double value, and then the Enter key. C. Enter an integer, an Enter key, a double value, and then the Enter key. D. Enter a numeric value with a decimal point, a space, an integer, and then the Enter key.3. If you enter 1 2 3, when you run this program, what will be the output?import java.util.Scanner;public class Test1 { public static void main(String[] args) { Scanner input = new Scanner(System.in); System.out.print("Enter three numbers: "); double number1 = input.nextDouble(); double number2 = input.nextDouble(); double number3 = input.nextDouble(); // Compute average double average = (number1 + number2 + number3) / 3; // Display result System.out.println(average); }} A. 1.0 B. 2.0 C. 3.0 D. 4.04. What is the exact output of the following code? double area = 3.5; System.out.print("area"); System.out.print(area); A. 3.53.5 B. 3.5 3.5 C. area3.5 D. area 3.55. Every letter in a Java keyword is in lowercase? A. true B. false6. Which of the following is a valid identifier? A. $343 B. class C. 9X D. 8+9 E. radius7 Which of the following are correct names for variables according to Java naming conventions? A. radius B. Radius C. RADIUS D. findArea E. FindArea8. Which of the following are correct ways to declare variables? A. int length; int width; B. int length, width; C. int length; width; D. int length, int width;9. ____________ is the Java assignment operator. A. == B. := C. = D. =:10. To assign a value 1 to variable x, you write A. 1 = x; B. x = 1; C. x := 1; D. 1 := x; E. x == 1;11. Which of the following assignment statements is incorrect? A. i = j = k = 1; B. i = 1; j = 1; k = 1; C. i = 1 = j = 1 = k = 1; D. i == j == k == 1;12. To improve readability and maintainability, you should declare _________ instead of using literal values such as 3.14159. A. variables B. methods C. constants D. classes13. Which of these data types requires the most amount of memory? A. long B. int C. short D. byte14. Analyze the following code:public class Test { public static void main(String[] args) { int n = 10000 * 10000 * 10000; System.out.println("n is " + n); }} A. The program displays n is 1000000000000 B. The result of 10000 * 10000 * 10000 is too large to be stored in an int variable n. This causes an overflow and the program is aborted. C. The result of 10000 * 10000 * 10000 is too large to be stored in an int variable n. This causes an overflow and the program continues to execute because Java does not report errors on overflow. D. The result of 10000 * 10000 * 10000 is too large to be stored in an int variable n. This causes an underflow and the program is aborted. E. The result of 10000 * 10000 * 10000 is too large to be stored in an int variable n. This causes an underflow and the program continues to execute because Java does not report errors on underflow. 15. What is the result of 45 / 4? A. 10 B. 11 C. 11.25 D. 1216. Which of the following expression results in a value 1? A. 2 % 1 B. 15 % 4 C. 25 % 5 D. 37 % 617. 25 % 1 is _____ A. 1 B. 2 C. 3 D. 4 E. 018. -25 % 5 is _____ A. 1 B. 2 C. 3 D. 4 E. 019. 24 % 5 is _____ A. 1 B. 2 C. 3 D. 4 E. 020. -24 % 5 is _____ A. -1 B. -2 C. -3 D. -4 E. 021. -24 % -5 is _____ A. 3 B. -3 C. 4 D. -4 E. 022. What is x after the following statements?int x = 2;int y = 1;x *= y + 1; A. x is 1. B. x is 2. C. x is 3. D. x is 4. 23. What is x after the following statements?int x = 1;x *= x + 1; A. x is 1. B. x is 2. C. x is 3. D. x is 4. 24. Which of the following statements are the same?(A) x -= x + 4(B) x = x + 4 - x(C) x = x - (x + 4) A. (A) and (B) are the same B. (A) and (C) are the same C. (B) and (C) are the same D. (A), (B), and (C) are the same 25. What is y displayed in the following code?public class Test { public static void main(String[] args) { int x = 1; int y = x++ + x; System.out.println("y is " + y); }} A. y is 1. B. y is 2. C. y is 3. D. y is 4.26. To assign a double variable d to a float variable x, you write A. x = (long)d B. x = (int)d; C. x = d; D. x = (float)d;27. What will be displayed by the following code?double x = 5.5;int y = (int)x;System.out.println("x is " + x + " and y is " + y); A. x is 5 and y is 6 B. x is 6.0 and y is 6.0 C. x is 6 and y is 6 D. x is 5.5 and y is 5 E. x is 5.5 and y is 5.028. What is the value of (double)5/2? A. 2 B. 2.5 C. 3 D. 2.0 E. 3.029. Which of the following expression results in 45.37? A. (int)(45.378 * 100) / 100 B. (int)(45.378 * 100) / 100.0 C. (int)(45.378 * 100 / 100) D. (int)(45.378) * 100 / 100.0 30. A Java character is stored in __________. A. one byte B. two bytes C. three bytes D. four bytes

Show full summary Hide full summary

Suggestions

CPU and Memory
LunaLovegood
Third Space Academia
k.fenbyhulse
IB SL Biology: Cells
mcgowan-w-10
C1 B1 & P1 Test
jodie00
ICT Key Terms Quiz - Part 1
Mr Mckinlay
Biological molecules
sadiaali363
LADY MACBETH TRAITS
Zealous
A2 Organic Chemistry - Reactions
Catrina Bowman
Continents & Oceans
Thomas Yoachim
Vampires, Dracula, and Morality Victorian Anxieties!
Anna-Maria Kotulski
TISSUE TYPES
Missi Shoup