Key Java Simple Data Types

Similar documents
Java Simple Data Types

Java Simple Data Types

JAVA OPERATORS GENERAL

Java provides a rich set of operators to manipulate variables. We can divide all the Java operators into the following groups:

Classes and Objects 3/28/2017. How can multiple methods within a Java class read and write the same variable?

(A) 99 ** (B) 100 (C) 101 (D) 100 initial integers plus any additional integers required during program execution

Programming Basics. Digital Urban Visualization. People as Flows. ia

Prof. Navrati Saxena TA: Rochak Sachan

Selenium Class 9 - Java Operators

Java provides a rich set of operators to manipulate variables. We can divide all the Java operators into the following groups:

C212 Early Evaluation Exam Mon Feb Name: Please provide brief (common sense) justifications with your answers below.

bitwise inclusive OR Logical logical AND && logical OR Ternary ternary? : Assignment assignment = += -= *= /= %= &= ^= = <<= >>= >>>=

Computational Expression

Fall CS 101: Test 2 Name UVA ID. Grading. Page 1 / 4. Page3 / 20. Page 4 / 13. Page 5 / 10. Page 6 / 26. Page 7 / 17.

Lab5. Wooseok Kim

(A) 99 (B) 100 (C) 101 (D) 100 initial integers plus any additional integers required during program execution

Building Java Programs

Building Java Programs

Place your name tag here

Lab5. Wooseok Kim

CS212 Midterm. 1. Read the following code fragments and answer the questions.

BASIC COMPUTATION. public static void main(string [] args) Fundamentals of Computer Science I

Basic operators, Arithmetic, Relational, Bitwise, Logical, Assignment, Conditional operators. JAVA Standard Edition

AP COMPUTER SCIENCE A

Chapter III. Java Simple Data Types. Chapter III Topics

Prelim 1. CS 2110, October 1, 2015, 5:30 PM Total Question Name True Short Testing Strings Recursion

CIS 1068 Design and Abstraction Spring 2017 Midterm 1a

1. Which of the following is the correct expression of character 4? a. 4 b. "4" c. '\0004' d. '4'

COMP 202 Java in one week

Datatypes, Variables, and Operations

More on methods and variables. Fundamentals of Computer Science Keith Vertanen

JAVA PROGRAMMING LAB. ABSTRACT In this Lab you will learn to define and invoke void and return java methods

CS 231 Data Structures and Algorithms, Fall 2016

Section 003 Fall CS 170 Exam 2. Name (print): Instructions:

Practice Questions for Final Exam: Advanced Java Concepts + Additional Questions from Earlier Parts of the Course

Introduction to Computer Programming

CS 139 Practice Midterm Questions #2

CS 101 Exam 2 Spring Id Name

Building Java Programs

Eng. Mohammed S. Abdualal

OWEN COMPUTER SCIENCE LESSONS L2RVW4 Pg 1. Lesson 2 Review #4. Matching. Match each description to the correct data type.

Midterm Exam CS 251, Intermediate Programming March 6, 2015

PROGRAMMING FUNDAMENTALS

b. Suppose you enter input from the console, when you run the program. What is the output?

CONDITIONAL EXECUTION

Introduction to OOP with Java. Instructor: AbuKhleif, Mohammad Noor Sep 2017

Final Exam CS 152, Computer Programming Fundamentals May 9, 2014

Building Java Programs. Chapter 2: Primitive Data and Definite Loops

Following is the general form of a typical decision making structure found in most of the programming languages:

Wentworth Institute of Technology. Engineering & Technology WIT COMP1000. Simple Control Flow: if-else statements

Java Programming Language. 0 A history

Question: Total Points: Score:

CSE115 / CSE503 Introduction to Computer Science I Dr. Carl Alphonce 343 Davis Hall Office hours:

CS 170 Exam 1. Version: B Fall Name (as on OPUS):

Lec 3. Compilers, Debugging, Hello World, and Variables

Data and Variables. Data Types Expressions. String Concatenation Variables Declaration Assignment Shorthand operators. Operators Precedence

cis20.1 design and implementation of software applications I fall 2007 lecture # I.2 topics: introduction to java, part 1

Selected Questions from by Nageshwara Rao

CS 455 Midterm Exam 1 Fall 2016 [Bono] Thursday, Sept. 29, 2016

CS 170 Exam 1. Version: C Fall Name (as on OPUS):

Basics of Java Programming

Operators & Expressions

OBJECT ORIENTED PROGRAMMING TYm. Allotted : 3 Hours Full Marks: 70

Lecture 2. COMP1406/1006 (the Java course) Fall M. Jason Hinek Carleton University

Topic 4 Expressions and variables

false, import, new 1 class Lecture2 { 2 3 "Data types, Variables, and Operators" 4

Data Types. 1 You cannot change the type of the variable after declaration. Zheng-Liang Lu Java Programming 52 / 87

CS111: PROGRAMMING LANGUAGE II

1. Find the output of following java program. class MainClass { public static void main (String arg[])

Units 0 to 4 Groovy: Introduction upto Arrays Revision Guide

Variables Chris Piech CS106A, Stanford University. Piech, CS106A, Stanford University

Review: Exam 1. Your First C++ Program. Declaration Statements. Tells the compiler. Examples of declaration statements

CS 101 Fall 2006 Midterm 1 Name: ID:

CS313D: ADVANCED PROGRAMMING LANGUAGE

Term 1 Unit 1 Week 1 Worksheet: Output Solution

Outline. Overview. Control statements. Classes and methods. history and advantage how to: program, compile and execute 8 data types 3 types of errors

REVIEW. The C++ Programming Language. CS 151 Review #2

More Things We Can Do With It! Overview. Circle Calculations. πr 2. π = More operators and expression types More statements

Chapter 3: Operators, Expressions and Type Conversion

1. [3 pts] What is your section number, the period your discussion meets, and the name of your discussion leader?

CP122 CS I. Iteration

CS 251 Intermediate Programming Methods and Classes

CS 251 Intermediate Programming Methods and More

COMP 202 Java in one week

Program Fundamentals

THE UNIVERSITY OF WESTERN AUSTRALIA. School of Computer Science & Software Engineering CITS1001 OBJECT-ORIENTED PROGRAMMING AND SOFTWARE ENGINEERING

THE UNIVERSITY OF WESTERN AUSTRALIA. School of Computer Science & Software Engineering CITS1001 OBJECT-ORIENTED PROGRAMMING AND SOFTWARE ENGINEERING

Operators Questions

CS-140 Fall 2017 Test 1 Version Practice Practie for Sept. 27, Name:

Question: Total Points: Score:

Question: Total Points: Score:

COMP 202. Java in one week

CSC 1214: Object-Oriented Programming

Chapter 2: Data and Expressions

Some Sample AP Computer Science A Questions - Solutions

Chapter 3 Selection Statements

Motivations. Chapter 3: Selections and Conditionals. Relational Operators 8/31/18. Objectives. Problem: A Simple Math Learning Tool

Basic Operations jgrasp debugger Writing Programs & Checkstyle

Computer Programming, I. Laboratory Manual. Experiment #2. Elementary Programming

CS-140 Fall 2017 Test 1 Version Practice Practie for Sept. 27, Name:

Transcription:

AP CS P w Java Unit 1 Multiple Choice Practice Key Java Simple Data Types This test includes program segments, which are not complete programs. Answer such questions with the assumption that the program segment is part of a correct program. 01. Which of the following are Java program keyword categories? ### (A) Reserved words, pre-defined identifiers and user-defined identifiers (B) Reserved pre-defined identifiers, reserved user-defined identifiers and library identifiers (C) void, static, println. (D) None of the above 02. Consider the two program segments below. Segment A Segment B int a; int a = 100; int b; int b = 200; a = 100; b = 200; What is true about the comparison of these two segments? (A) Segment A is correct and segment B is not correct. (B) Segment A is incorrect and segment B is correct. ### (C) Segment A and segment B are both correct. (D) segment A and segment B are both incorrect. Exposure Java 2013, PreAPCS Edition Chapter 3 Test Page 1 Updated: 05-22-13

03. Consider the two program segments below. Segment A Segment B int a; int a = 100; int b; int b = 200; System.out.println(a); System.out.println(a); System.out.println(b); System.out.println(b); What is true about the comparison of these two segments? (A) Segment A is correct and segment B is not correct. ### (B) Segment A is incorrect and segment B is correct. (C) Segment A and segment B are both correct. (D) segment A and segment B are both incorrect. 04. Which of the following are examples of reserved words? ### (A) public, void and static (B) System, out and println (C) System, public and void (D) print, println and args 05. Which of the following is used to store integers? (A) boolean (B) char (C) double ### (E) String 06. Which of the following is used to store real numbers? (A) boolean (B) char ### (C) double (E) String Exposure Java 2013, PreAPCS Edition Chapter 3 Test Page 2 Updated: 05-22-13

07. Which of the following would be ideal for storing a Middle Initial? (A) boolean ### (B) char (C) double (E) String 08. Which of the following would you need to store someone's name? (A) boolean (B) char (C) double ### (E) String 09. Which of the following can only store 2 possible values: true or false? ### (A) boolean (B) char (C) double (E) String 10. Which of the following stores 1 single character? (A) boolean ### (B) char (C) double (E) String 11. Which of the following can store words, phrases, or sentences? (A) boolean (B) char (C) double ### (E) String Exposure Java 2013, PreAPCS Edition Chapter 3 Test Page 3 Updated: 05-22-13

12. Which of the following Java data types is the most like the Lego NXT Number data type? (A) boolean (B) char ### (C) double (E) String 13. Which of the following Java data types is the most like the Lego NXT Text data type? (A) boolean (B) char (C) double ### (E) String 14. Which of the following Java data types is the most like the Lego NXT Logic data type? ### (A) boolean (B) char (C) double (E) String 15. Which of the following are Java Keywords? (A) Reserved Words (B) Pre-defined Identifiers (C) User-defined Identifiers ### (D) All of the above 16. Assume x is defined as an int. Which of the following will add 1 to x? (A) x++; (B) x+=1; (C) x=x+1; ### (D) All of the above Exposure Java 2013, PreAPCS Edition Chapter 3 Test Page 4 Updated: 05-22-13

17. Assume x is defined as an int. Which of the following will subtract 1 from x? (A) x--; (B) x-=1; (C) x=x-1; ### (D) All of the above 18. Which operator is used for multiplication? (A) + (B) ### (C) * (D) / (E) % 19. Which operator will find the quotient when performing division? (A) + (B) - (C) * ### (D) / (E) % 20. Which operator will find the remainder when performing division? (A) + (B) - (C) * (D) / ### (E) % 21. Assume x is defined as an int. Which of the following will double the value in x? (A) x = x + x; (B) x += x; (C) x = x * 2; (D) x *= 2; ### (E) All of the above Exposure Java 2013, PreAPCS Edition Chapter 3 Test Page 5 Updated: 05-22-13

22. 7 is a(n) value. (A) char (B) double ### (C) int (D) String 23. 7.0 is a(n) value. (A) char ### (B) double (C) int (D) String 24. '7' is a(n) value. ### (A) char (B) double (C) int (D) String 25. "7" is a(n) value. (A) char (B) double (C) int ### (D) String Exposure Java 2013, PreAPCS Edition Chapter 3 Test Page 6 Updated: 05-22-13

26. What is the output of this program? (A) 2 (B) 2.5 (C) 150 (D) 25000 ### (E) 250 100 27. What is the output of this program? (A) 2 (B) 2.5 (C) 150 (D) 25000 ### (E) 250 100 28. What is the output of this program? (A) 2 (B) 2.5 ### (C) 150 (D) 25000 (E) 250 100 29. What is the output of this program? ### (A) 2 (B) 2.5 (C) 150 (D) 25000 (E) 250 100 Exposure Java 2013, PreAPCS Edition Chapter 3 Test Page 7 Updated: 05-22-13

30. What is the output of this program? (A) John (B) John Smith ### (C) JohnSmith (D) Smith, John (E) John C. Smith 31. What is the output of this program? (A) John ### (B) John Smith (C) JohnSmith (D) Smith, John (E) John C. Smith 32. What is the output of this program? (A) John (B) John Smith (C) JohnSmith ### (D) Smith, John (E) John C. Smith 33. What is the output of this program? (A) John (B) John Smith ### (C) JohnSmith (D) Smith, John (E) John C. Smith Exposure Java 2013, PreAPCS Edition Chapter 3 Test Page 8 Updated: 05-22-13

34. What is the output of this program? (A) 100 (B) 200 (C) 300 ### (D) 100200 (E) 100 200 35. What is the output of this program? (A) 100 (B) 200 ### (C) 300 (D) 100200 (E) 100 200 36. What is the output of this program? ### (A) (B) (C) No Output (D) Compiler Error 37. What is the output of this program? (A) (B) (C) No Output ### (D) Compiler Error Exposure Java 2013, PreAPCS Edition Chapter 3 Test Page 9 Updated: 05-22-13

38. Which of the following is the single-line comment symbol? ### (A) // (B) \\ (C) /* (D) */ 39. Which of the following is the begin-multiple-line comment symbol? (A) // (B) \\ ### (C) /* (D) */ 40. Which of the following is the end-multiple-line comment symbol? (A) // (B) \\ (C) /* ### (D) */ 41. What is the value of x after this statement? (A) 26 ### (B) 38 (C) 48 (D) 50 (E) 66 int x = 3 + 7 * 5; 42. What is the value of x after this statement? (A) 26 ### (B) 38 (C) 48 (D) 50 (E) 66 int x = 3 + (7 * 5); Exposure Java 2013, PreAPCS Edition Chapter 3 Test Page 10 Updated: 05-22-13

43. What is the value of x after this statement? (A) 26 (B) 38 (C) 48 ### (D) 50 (E) 66 int x = (3 + 7) * 5; 44. What is the value of x after this statement? (A) 2 (B) 4 ### (C) 6 (D) 8 (E) 12 int x = (4 + 8) / 2; 45. What is the value of x after this statement? (A) 2 (B) 4 (C) 6 ### (D) 8 (E) 12 int x = 4 + 8 / 2; 46. What is the value of x after this statement? (A) 2 (B) 4 (C) 6 ### (D) 8 (E) 12 int x = 4 + (8 / 2); Exposure Java 2013, PreAPCS Edition Chapter 3 Test Page 11 Updated: 05-22-13

47. What is the value of x after this statement? int x = 2 / 5; ### (A) 0 (B) 0.4 (C) 0.5 (D) 2 (E) 2.5 48. What is the value of x after this statement? (A) 0 ### (B) 0.4 (C) 0.5 (D) 2 (E) 2.5 double x = 2.0 / 5.0; 49. What is the output of this program segment? double PI = 3.14159; System.out.println(PI); (A) PI ### (B) 3.14159 (C) PI = 3.14159 (D) PI = PI (E) Compile Error 50. What is the output of this program segment? double PI = 3.14159; System.out.println("PI"); ### (A) PI (B) 3.14159 (C) PI = 3.14159 (D) PI = PI (E) Compile Error Exposure Java 2013, PreAPCS Edition Chapter 3 Test Page 12 Updated: 05-22-13

51. What is the output of this program segment? double PI = 3.14159; System.out.println("PI = " + PI); (A) PI (B) 3.14159 ### (C) PI = 3.14159 (D) PI = PI (E) Compile Error 52. What is the output of this program segment? double PI; System.out.println(PI); (A) PI (B) 3.14159 (C) PI = 3.14159 (D) PI = PI ### (E) Compile Error 53. What is the output of this program segment? int q = 11; q--; q--; q--; q--; System.out.println(q); ### (A) 7 (B) 8 (C) 9 (D) 10 (E) 11 Exposure Java 2013, PreAPCS Edition Chapter 3 Test Page 13 Updated: 05-22-13

54. What is the output of this program segment? (A) 7 (B) 8 (C) 9 (D) 10 ### (E) 11 int q = 11; q--; q++; q--; q++; System.out.println(q); 55. What is the output of this program segment? (A) 7 ### (B) 8 (C) 9 (D) 10 (E) 11 int q = 4; q *= 2; System.out.println(q); 56. What is the output of this program segment? (A) 7 (B) 8 ### (C) 9 (D) 10 (E) 11 int q = 24; q /= 3; q++; System.out.println(q); Exposure Java 2013, PreAPCS Edition Chapter 3 Test Page 14 Updated: 05-22-13

57. What is the output of this program segment? ### (A) 5 (B) 6 (C) 7 (D) 8 (E) 9 int q = 24; q /= 4; q--; System.out.println(q); 58. What is the output of this program segment? ### (A) 5 (B) 6 (C) 7 (D) 8 (E) 9 int a = 2; int b = 3; a++; b--; int c = a + b; System.out.println(c); 59. What is the output of this program segment? (A) 6 (B) 7 (C) 12 ### (D) 18 (E) 72 int a = 4; int b = 3; a *= 3; b *= 2; int c = a + b; System.out.println(c); Exposure Java 2013, PreAPCS Edition Chapter 3 Test Page 15 Updated: 05-22-13

60. What is the output of this program segment? int a, b; a = b = 30; a /= 3; b /= 5; int c = a - b; System.out.println(c); ### (A) 4 (B) 6 (C) 8 (D) 10 (E) 30 Exposure Java 2013, PreAPCS Edition Chapter 3 Test Page 16 Updated: 05-22-13