AP CS Fall Semester Final
|
|
- Kristopher Lane
- 6 years ago
- Views:
Transcription
1 Name: Class: Date: AP CS Fall Semester Final Multiple Choice Identify the choice that best completes the statement or answers the question. 1. What is printed by the following code? int k = 3; for (int pj = 5; pj <= 100; pj++) k = pj + 1; System.out.println(3 * k + pj); a. Won t compile b. Never prints, endless loop c d What is printed by the following code? int jj = 2; do int gk = 1 + jj++; while(jj < 10); System.out.println(gk); a. Won t compile b. Never prints, endless loop c. 45 d String sss = I like school ; Using the two paramater form of substring, which line of code will print the last character of sss? 4. String sss = I like school ; Using the one paramater form of substring, which line of code will print the last character of sss? a. System.out.println( sss.substring(11) ); b. System.out.println( sss.substring(12) ); c. System.out.println( sss.substring(13) ); d. System.out.println( sss.substring(12, 14) ); 5. String sss = I like school ; Using charat, which line of code will print the last character of sss? a. System.out.println( sss.charat(11) ); b. System.out.println( sss.charat(12) ); c. System.out.println( sss.charat(13) ); d. System.out.println( sss.charat(14) ); 6. Assume s is a String. Using the two-parameter form of substring, which line of code will print the last character of s? a. System.out.println( s.substring( s.length( ) - 1, s.length( ) ) ); b. System.out.println( s.substring( s.length( ), s.length( ) ) ); c. System.out.println( s.substring( s.length( ) + 1, s.length( ) ) ); d. System.out.println( s.substring( s.length( ) - 1, s.length ) ); a. System.out.println( sss.substring(12, 13) ); b. System.out.println( sss.substring(12) ); c. System.out.println( sss.substring(12, 11) ); d. System.out.println( sss.substring(12, 14) ); 1
2 Name: 7. Assume s is a String. Using the one-parameter form of substring, which line of code will print the last character of s? a. System.out.println( s.substring(s.length( ) - 1 ) ); b. System.out.println( s.substring(s.length( ) + 1 ) ); c. System.out.println( s.substring(s.length( ) ) ); d. System.out.println( s.substring(s.length - 1 ) ); 8. Assume s is a String. Using charat, which line of code will print the last character of s? a. System.out.println( s.charat(s.length 1 ) ); b. System.out.println( s.charat(s.length( ) ) ); c. System.out.println( s.charat(s.length( ) +1 ) ); d. System.out.println( s.charat(s.length( ) 1 ) ); 9. What is printed by the following? String p = ABCDE ; System.out.println( X + p.substring(2,2) + X ); a. Illegal, won t compile b. XBX c. XCX d. XX 10. What s printed by the code below? int k = 23; System.out.println(Integer.toBinaryString( k )); a b c d What code that will printout the hex equivalent of int m? a. System.out.println( Integer.toString(m, hex ) ); b. System.out.println( Integer.toHexString(m) ); c. System.out.println( Integer.toString(m) ); d. System.out.println( Integer.toString(m, 16) ); 12. What code that will printout the octal equivalent of int m? a. System.out.println( Integer.toString(m, oct ) ); b. System.out.println( Integer.toOctalString(m) ); c. System.out.println( Integer.toString(m) ); d. System.out.println( Integer.toString(m, 8) ); 13. What is printed by the following? String s1 = "m"; String s2 = "Z"; System.out.println(s1.compareTo(s2)); a. A positive number b. A negative number c. 0 d. true e. false 14. What is printed by the following? int x = 9; double y = 1.3; String s = Felix ; System.out.println(x + y + s + x + y); a. 91.3Felix91.3 b. 10.3Felix91.3 c. 91.3Felix10.3 d. Illegal, won t compile 2
3 Name: 15. What code that will print the following? Cat\"hello"X'm' a. System.out.println("Cat//\"hello\"X\'m\'"); b. System.out.println("Cat///"hello/"X\'m/'"); c. System.out.println("Cat\\\"hello\"X\'m\'"); d. System.out.println("Cat\"hello"X'm'"); 16. What are all objects equal to before they are initialized? a. null b. zero c. d. Illegal. They must be initialized when declared. 17. What code replaces <##> below so as to make it skip the remaining code in the loop, but still continue looping? for(j = 0; j < 10; j++) if (j >= 5) <##> m = j *2; m =j + 2; sum = sum + m; a. continue; b. break; c. exit; d. stop; 18. What is printed by the following code? int x = 5; double y = (x >8)? Math.pow(x,2) : Math.pow(x,3); System.out.println(y); a. Illegal, won t compile b. 125 c d. 1.25E0 19. What is printed by the following code? int x = 462; if(!x > 0) System.out.println( positive ); else System.out.println( negative ); a. Illegal, won t compile b. positive c. negative d. Nothing is printed 20. What is printed by the following? System.out.println(17.2%4); a. 1.2 b. 4.3 c. 1 d
4 Name: 21. Does the conditional part of the if below return a true, false, or give an error? a. true b. false c. error int x = 3, y = 5; if ( (x < 8 ) && (y > -1) ) some code 22. Of which of the following is y *= z + m the equivalent? a. y = y * (z + m); b. y = y * z + m; c. Neither of these 23. What is printed by the following? System.out.println(-12%5); a. 2 b. -2 c. Illegal, won t compile d What is printed by the following? System.out.println( 12%(-5) ); a. 2 b. -2 c. Illegal, won t compile d What is printed by the following? System.out.println( -12%(-5) ); a. 2 b. -2 c. Illegal, won t compile d What is printed by the following? int x = 7; int y = 3; double d = (double)(x/y); System.out.println(d); a. 2 b. 2.0 c d. Illegal, won t compile 27. What is printed by the following? int x = 7; int y = 3; double d = (double)x/y; System.out.println(d); a. 2 b. 2.0 c d. Illegal, won t compile 28. Specify the accessibility provided by public: a. Accessible from anywhere b. Accessible from just within its own class c. All methods of classes in the same package can access the feature. This is the default access control if none is specified. d. Access is permitted by methods of the same class, subclasses, and classes in the same package. 29. Specify the accessibility provided by private: a. Accessible from anywhere b. Accessible from just within its own class c. All methods of classes in the same package can access the feature. This is the default access control if none is specified. d. Access is permitted by methods of the same class, subclasses, and classes in the same package. 4
5 Name: 30. What is printed by System.out.println(10 / 4 * 50); a..05 b. 125 c d What code will convert double d to a String and store the result in s. a. String s = (String)d; b. String s = d + ; c. String s = + d; d. Both A and C e. Both B and C 32. What does the following print? double p = 3.07; double q = 2.9; int count = 2; if ( (p / q == 1) && (count-- < 59))... System.out.println(count); a. 1 b. 2 c. 3 d What does the following print? double p = 3.07; double q = 2.9; int count = 2; if ( (p / q == 1) (count-- < 59))... System.out.println(count); a. 1 b. 2 c. 3 d What does the following print? double p = 3.07; double q = 3.07; int count = 2; if ( (p / q == 1) && (count-- < 59))... System.out.println(count); a. 1 b. 2 c. 3 d. Illegal, won t compile e. Not enough information 35. Suppose you wish to find the index of the first occurrence of the character A (starting with index 4) in String mystring. Which line of code will store this value in the integer k. a. int k = mystring.indexof(65, 4); b. int k = mystring.indexof( A, 4); c. int k = mystring.lastindexof(65); d. int k = mystring.charat(65, 4); e. Both A and B 36. Which line of code will find the first occurrence of ee in the sentence stored in String sentc. Store the index in jj. a. int jj = sentc.indexof(ascii(69), 2); b. int jj = sentc.indexof(69,69); c. int jj = sentc.indexof( ee ); d. int jj = sentc.index( ee ); 37. What is another name for method? a. function b. parameters c. signature d. header 38. What is another name for header? a. function b. parameters c. signature d. method 5
6 Name: 39. What is another name for function? a. method b. parameters c. signature d. header 40. What is another name for signature? a. function b. parameters c. method d. header 41. To what is a numeric data member automatically initialized (in the absence of specific initialization)? a. 0 or 0.0 b. 1 c. null d. Nothing, not initialized 42. To what is a local numeric variable automatically initialized (in the absence of specific initialization)? a. 0 or 0.0 b. 1 c. null d. Nothing, not initialized 43. When Boolean OR-ing two boolean expressions, when is only one expression evaluated? a. When the left expression is true b. When the right expression is true c. When the left expression is false d. When the right expression is false 44. When Boolean AND-ing two boolean expressions, when is only one expression evaluated? 45. In order to determine if the character at index j of String sp is a whitespace character, which of the following would return the appropriate boolean? a. Character.sp.isWhitespace(j) b. sp.charat(j).iswhitespace c. Character.isWhitespace(sp.charAt(j)) d. sp.charat(iswhitespace( )) 46. If c is of type char and i is of type int, is the following legal or illegal? i = c; a. Legal b. Illegal 47. If c is of type char and i is of type int, is the following legal or illegal? a. Legal b. Illegal c = (char)i; 48. If c is of type char and i is of type int, is the following legal or illegal? c = i; a. Legal b. Illegal 49. What is the range of ASCII codes for the following? The digits 0,1-9 a b c d a. When the left expression is true b. When the right expression is true c. When the left expression is false d. When the right expression is false 6
7 Name: 50. What is the range of ASCII codes for the following? The letters a z a b c d What is the range of ASCII codes for the following? The letters A Z a b c d What is returned by Math.ceil( )? a b c d What is returned by Math.floor( )? a b c d What is returned by Math.round(7/2)? a. 4 b. 3.5 c. 3.0 d. 3 7
8 AP CS Fall Semester Final Answer Section MULTIPLE CHOICE 1. ANS: A The scope of pj is limited to inside the loop, starting with for and ending with. 2. ANS: A The scope of gk is limited to inside the loop, starting with do and ending with. 3. ANS: A Play around with these in BlueJ s Code Pad (View Show Code Pad) 4. ANS: B 5. ANS: B 6. ANS: A 7. ANS: A 8. ANS: D 9. ANS: D Start at index 2, up to but not including index 2, is an empty String: 10. ANS: E...answer is ANS: E...both B and D 12. ANS: E...both B and D 13. ANS: A See ASCII table for lesson on char. Think of compareto as s1 - s2, in that order. 14. ANS: B + signs are evaluated left to right. x+y evaluates to Felix results in a String, 10.3Felix. Append x to the end results in 10.3Felix9. Concatenate y results in choice b. 1
9 15. ANS: C \,,, etc. are escape chacters. They have special meanings. To include them in Strings, you have to put a backslash (\) in front. 16. ANS: A 17. ANS: A continue means skipping the rest of a loop, straight to the step expression, j ANS: C The second line can be rewritten as: double y; if (x > 8) y = Math.pow(x,2); else y = Math.pow(x,3); 19. ANS: A! has top priority here. (Unary operators, like! and -, usually have precedent). Should be (!(x>0)). 20. ANS: A The multiple of 4 closest to 17.2 is = ANS: A 22. ANS: A 23. ANS: B Closest multiple of 5 to -12 is ANS: A Closest multiple of -5 to 12 is 10. Another way of thinking is, if the questions asks 10%(-5), the answer is 0, because (-5)(-2) = ANS: B Same as (-12)%(-5). 26. ANS: B...The parenthesis around x/y creates a little world of its own and since x and y are both integers, integer arithmetic is done giving 2 (not ). This answer is then cast into a double. 2
10 27. ANS: C...Only the x is cast as a double. x/y is now done with double arithmetic since x is a double. Casting has high precedence. 28. ANS: A 29. ANS: B 30. ANS: D * and /, + and _, have same precedence, so evaluate from left to right. int/int = int. 31. ANS: E Primitive types can t be cast into objects like String, or vice versa. 32. ANS: B p/q is not equal to 1. So false && (...) will never be true. Java short-circuits and skips the whole if statement. It doesn t bother to evaluate count-- < 59, because it doesn t matter. So count remains the same value. 33. ANS: A p/q is not equal to 1. So the value of the if condition depends on whether count-- < 59. BTW, avoid writing programs like this unless you re an expert at the differences between x-- and --x. It actually compares count < 59, then do count ANS: E p/q is 1.0. Well, it could also be or Floating point numbers are not stored exactly in most programming languages. So it s a really bad idea to compare them to integers. Include a margin of error. 35. ANS: E... both A and B 36. ANS: C Strings are objects. No ASCII table. 37. ANS: A... both A and B 38. ANS: C. 3
11 39. ANS: A... both A and B 40. ANS: D 41. ANS: A A Circle class has an instance variable radius. A BankAccount class has an object variable balance and name. (These are the same names for data member. They are declared inside the class but outside all the methods.) radius and balance are set to default values if not initialized. 42. ANS: D Local variables are declared inside a method. In the circle class s area() method, we may temporarily store the area into a new variable double a before returning it. But if we don t initialize a, it doesn t have any values. The compiler would complain. 43. ANS: A Look up short-circuiting. 44. ANS: C Look up short-circuiting. 45. ANS: C 46. ANS: A char goes from 0 to 127, so no problem storing it as an int. 47. ANS: A i could be 65 ( A ), or This code will always compile, but the latter would result in a run-time exception. 48. ANS: B 49. ANS: A 50. ANS: D 51. ANS: C 52. ANS: A What is the smallest number greater than (less negative) -1032? Return it as a double. 53. ANS: E... answer is
12 54. ANS: C 7/2 is integer arithmetic and gives 3. After rounding, it s still 3.0 5
int j = 0, sum = 0; for (j = 3; j <= 79; j++) { sum = sum + j; System.out.println(sum); //Show the progress as we iterate thru the loop.
11-1 One of the most important structures in Java is the -loop. A loop is basically a block of code that is with certain rules about how to start and how to end the process. Suppose we want to sum up all
More informationJava Review. Fundamentals of Computer Science
Java Review Fundamentals of Computer Science Link to Head First pdf File https://zimslifeintcs.files.wordpress.com/2011/12/h ead-first-java-2nd-edition.pdf Outline Data Types Arrays Boolean Expressions
More informationExpressions and Data Types CSC 121 Spring 2015 Howard Rosenthal
Expressions and Data Types CSC 121 Spring 2015 Howard Rosenthal Lesson Goals Understand the basic constructs of a Java Program Understand how to use basic identifiers Understand simple Java data types
More informationcis20.1 design and implementation of software applications I fall 2007 lecture # I.2 topics: introduction to java, part 1
topics: introduction to java, part 1 cis20.1 design and implementation of software applications I fall 2007 lecture # I.2 cis20.1-fall2007-sklar-leci.2 1 Java. Java is an object-oriented language: it is
More informationExpressions and Data Types CSC 121 Fall 2015 Howard Rosenthal
Expressions and Data Types CSC 121 Fall 2015 Howard Rosenthal Lesson Goals Understand the basic constructs of a Java Program Understand how to use basic identifiers Understand simple Java data types and
More informationSequence structure. The computer executes java statements one after the other in the order in which they are written. Total = total +grade;
Control Statements Control Statements All programs could be written in terms of only one of three control structures: Sequence Structure Selection Structure Repetition Structure Sequence structure The
More informationIntroduction to Programming Using Java (98-388)
Introduction to Programming Using Java (98-388) Understand Java fundamentals Describe the use of main in a Java application Signature of main, why it is static; how to consume an instance of your own class;
More informationPROGRAMMING FUNDAMENTALS
PROGRAMMING FUNDAMENTALS Q1. Name any two Object Oriented Programming languages? Q2. Why is java called a platform independent language? Q3. Elaborate the java Compilation process. Q4. Why do we write
More informationLexical Considerations
Massachusetts Institute of Technology Department of Electrical Engineering and Computer Science 6.035, Fall 2005 Handout 6 Decaf Language Wednesday, September 7 The project for the course is to write a
More informationCMPT 125: Lecture 3 Data and Expressions
CMPT 125: Lecture 3 Data and Expressions Tamara Smyth, tamaras@cs.sfu.ca School of Computing Science, Simon Fraser University January 3, 2009 1 Character Strings A character string is an object in Java,
More informationFull file at
Java Programming: From Problem Analysis to Program Design, 3 rd Edition 2-1 Chapter 2 Basic Elements of Java At a Glance Instructor s Manual Table of Contents Overview Objectives s Quick Quizzes Class
More informationObjects and Types. COMS W1007 Introduction to Computer Science. Christopher Conway 29 May 2003
Objects and Types COMS W1007 Introduction to Computer Science Christopher Conway 29 May 2003 Java Programs A Java program contains at least one class definition. public class Hello { public static void
More informationA Java program contains at least one class definition.
Java Programs Identifiers Objects and Types COMS W1007 Introduction to Computer Science Christopher Conway 29 May 2003 A Java program contains at least one class definition. public class Hello { public
More informationChapter 2 Part 2 Edited by JJ Shepherd, James O Reilly
Basic Computation Chapter 2 Part 2 Edited by JJ Shepherd, James O Reilly Parentheses and Precedence Parentheses can communicate the order in which arithmetic operations are performed examples: (cost +
More informationJAVA Programming Fundamentals
Chapter 4 JAVA Programming Fundamentals By: Deepak Bhinde PGT Comp.Sc. JAVA character set Character set is a set of valid characters that a language can recognize. It may be any letter, digit or any symbol
More informationJava Bytecode (binary file)
Java is Compiled Unlike Python, which is an interpreted langauge, Java code is compiled. In Java, a compiler reads in a Java source file (the code that we write), and it translates that code into bytecode.
More informationIEEE Floating-Point Representation 1
IEEE Floating-Point Representation 1 x = ( 1) s M 2 E The sign s determines whether the number is negative (s = 1) or positive (s = 0). The significand M is a fractional binary number that ranges either
More informationMidterm I - CSE11 Fall 2013 CLOSED BOOK, CLOSED NOTES 50 minutes, 100 points Total.
Midterm I - CSE11 Fall 2013 CLOSED BOOK, CLOSED NOTES 50 minutes, 100 points Total. Name: ID: Problem 1) (8 points) For the following code segment, what are the values of i, j, k, and d, after the segment
More informationIn Java, data type boolean is used to represent Boolean data. Each boolean constant or variable can contain one of two values: true or false.
CS101, Mock Boolean Conditions, If-Then Boolean Expressions and Conditions The physical order of a program is the order in which the statements are listed. The logical order of a program is the order in
More informationCS101 Part 2: Practice Questions Algorithms on Arrays, Classes and Objects, String Class, Stack Class
CS1 Part 2: Algorithms on Arrays, Classes and Objects, String Class, Stack Class 1. Write a method that, given two sorted arrays of integers, merges the two arrays into a single sorted array that is returned.
More informationLecture Set 4: More About Methods and More About Operators
Lecture Set 4: More About Methods and More About Operators Methods Definitions Invocations More arithmetic operators Operator Side effects Operator Precedence Short-circuiting main method public static
More informationLexical Considerations
Massachusetts Institute of Technology Department of Electrical Engineering and Computer Science 6.035, Spring 2010 Handout Decaf Language Tuesday, Feb 2 The project for the course is to write a compiler
More informationObject oriented programming. Instructor: Masoud Asghari Web page: Ch: 3
Object oriented programming Instructor: Masoud Asghari Web page: http://www.masses.ir/lectures/oops2017sut Ch: 3 1 In this slide We follow: https://docs.oracle.com/javase/tutorial/index.html Trail: Learning
More informationObject-oriented programming. and data-structures CS/ENGRD 2110 SUMMER 2018
Object-oriented programming 1 and data-structures CS/ENGRD 2110 SUMMER 2018 Lecture 1: Types and Control Flow http://courses.cs.cornell.edu/cs2110/2018su Lecture 1 Outline 2 Languages Overview Imperative
More informationLanguage Reference Manual
Espresso Language Reference Manual 10.06.2016 Rohit Gunurath, rg2997 Somdeep Dey, sd2988 Jianfeng Qian, jq2252 Oliver Willens, oyw2103 1 Table of Contents Table of Contents 1 Overview 3 Types 4 Primitive
More informationb. Suppose you enter input from the console, when you run the program. What is the output?
Part I. Show the printout of the following code: (write the printout next to each println statement if the println statement is executed in the program). a. Show the output of the following code: public
More informationfalse, import, new 1 class Lecture2 { 2 3 "Data types, Variables, and Operators" 4
1 class Lecture2 { 2 3 "Data types, Variables, and Operators" 4 5 } 6 7 // Keywords: 8 byte, short, int, long, char, float, double, boolean, true, false, import, new Zheng-Liang Lu Java Programming 44
More informationZheng-Liang Lu Java Programming 45 / 79
1 class Lecture2 { 2 3 "Elementray Programming" 4 5 } 6 7 / References 8 [1] Ch. 2 in YDL 9 [2] Ch. 2 and 3 in Sharan 10 [3] Ch. 2 in HS 11 / Zheng-Liang Lu Java Programming 45 / 79 Example Given a radius
More informationCT 229 Java Syntax Continued
CT 229 Java Syntax Continued 29/09/2006 CT229 Lab Assignments One Week Extension for Lab Assignment 1. Due Date: Oct 8 th Before submission make sure that the name of each.java file matches the name given
More informationSlide 1 CS 170 Java Programming 1 More on Strings Duration: 00:00:47 Advance mode: Auto
CS 170 Java Programming 1 More on Strings Working with the String class Slide 1 CS 170 Java Programming 1 More on Strings Duration: 00:00:47 What are Strings in Java? Immutable sequences of 0 n characters
More informationExam 1 Prep. Dr. Demetrios Glinos University of Central Florida. COP3330 Object Oriented Programming
Exam 1 Prep Dr. Demetrios Glinos University of Central Florida COP3330 Object Oriented Programming Progress Exam 1 is a Timed Webcourses Quiz You can find it from the "Assignments" link on Webcourses choose
More informationChapter 3: Operators, Expressions and Type Conversion
101 Chapter 3 Operators, Expressions and Type Conversion Chapter 3: Operators, Expressions and Type Conversion Objectives To use basic arithmetic operators. To use increment and decrement operators. To
More informationPlace your name tag here
CS 170 Exam 1 Section 001 Spring 2015 Name: Place your name tag here Instructions: Keep your eyes on your own paper and do your best to prevent anyone else from seeing your work. Do NOT communicate with
More informationVARIABLES AND TYPES CITS1001
VARIABLES AND TYPES CITS1001 Scope of this lecture Types in Java the eight primitive types the unlimited number of object types Values and References The Golden Rule Primitive types Every piece of data
More informationComputer Programming CS F111
Computer Programming CS F111 BITS Pilani Dubai Campus NAND KUMAR Basics of C Programming BITS Pilani Dubai Campus Write a program that 1. Asks 5 marks from the user, find the average of the marks and print
More informationANSWERS. Birkbeck (University of London) Software and Programming 1 In-class Test Feb Student Name Student Number. Answer all questions
Birkbeck (University of London) Software and Programming 1 In-class Test 1.1 9 Feb 2017 Student Name Student Number Answer all questions 1. Consider the following sequence of Java statements: int m = 3;
More informationCOMP-202 Unit 2: Java Basics. CONTENTS: Using Expressions and Variables Types Strings Methods
COMP-202 Unit 2: Java Basics CONTENTS: Using Expressions and Variables Types Strings Methods Assignment 1 Assignment 1 posted on WebCt and course website. It is due May 18th st at 23:30 Worth 6% Part programming,
More informationDATA TYPES AND EXPRESSIONS
DATA TYPES AND EXPRESSIONS Outline Variables Naming Conventions Data Types Primitive Data Types Review: int, double New: boolean, char The String Class Type Conversion Expressions Assignment Mathematical
More informationfalse, import, new 1 class Lecture2 { 2 3 "Data types, Variables, and Operators" 4
1 class Lecture2 { 2 3 "Data types, Variables, and Operators" 4 5 } 6 7 // Keywords: 8 byte, short, int, long, char, float, double, boolean, true, false, import, new Zheng-Liang Lu Java Programming 44
More informationAccelerating Information Technology Innovation
Accelerating Information Technology Innovation http://aiti.mit.edu Cali, Colombia Summer 2012 Lesson 02 Variables and Operators Agenda Variables Types Naming Assignment Data Types Type casting Operators
More informationControl Structures in Java if-else and switch
Control Structures in Java if-else and switch Lecture 4 CGS 3416 Spring 2017 January 23, 2017 Lecture 4CGS 3416 Spring 2017 Selection January 23, 2017 1 / 26 Control Flow Control flow refers to the specification
More informationMcGill University School of Computer Science COMP-202A Introduction to Computing 1
McGill University School of Computer Science COMP-202A Introduction to Computing 1 Midterm Exam Thursday, October 26, 2006, 18:00-20:00 (6:00 8:00 PM) Instructors: Mathieu Petitpas, Shah Asaduzzaman, Sherif
More informationfalse, import, new 1 class Lecture2 { 2 3 "Data types, Variables, and Operators" 4
1 class Lecture2 { 2 3 "Data types, Variables, and Operators" 4 5 } 6 7 // Keywords: 8 byte, short, int, long, char, float, double, boolean, true, false, import, new Zheng-Liang Lu Java Programming 44
More information1 Lexical Considerations
Massachusetts Institute of Technology Department of Electrical Engineering and Computer Science 6.035, Spring 2013 Handout Decaf Language Thursday, Feb 7 The project for the course is to write a compiler
More informationAP Computer Science A
AP Computer Science A 1st Quarter Notes Table of Contents - section links Click on the date or topic below to jump to that section Date : 9/8/2017 Aim : Java Basics Objects and Classes Data types: Primitive
More informationCS164: Programming Assignment 2 Dlex Lexer Generator and Decaf Lexer
CS164: Programming Assignment 2 Dlex Lexer Generator and Decaf Lexer Assigned: Thursday, September 16, 2004 Due: Tuesday, September 28, 2004, at 11:59pm September 16, 2004 1 Introduction Overview In this
More informationVariables, Types, Operations on Numbers
Variables, Types, Operations on Numbers CSE 1310 Introduction to Computers and Programming Vassilis Athitsos University of Texas at Arlington Updated 9/6/16 1 Summary Variable declaration, initialization,
More informationJava s String Class. in simplest form, just quoted text. used as parameters to. "This is a string" "So is this" "hi"
1 Java s String Class in simplest form, just quoted text "This is a string" "So is this" "hi" used as parameters to Text constructor System.out.println 2 The Empty String smallest possible string made
More informationCasting. References. References
Casting February 2, 2018 1 References Let A be a class and B be a subclass of A. A reference variable of type A may refer to an object of type either A or B. A reference variable of type B may refer to
More informationProgramming with Java
Programming with Java Data Types & Input Statement Lecture 04 First stage Software Engineering Dep. Saman M. Omer 2017-2018 Objectives q By the end of this lecture you should be able to : ü Know rules
More informationString Computation Program
String Computation Program Reference Manual Scott Pender scp2135@columbia.edu COMS4115 Fall 2012 10/31/2012 1 Lexical Conventions There are four kinds of tokens: identifiers, keywords, expression operators,
More informationPrimitive Types. Four integer types: Two floating-point types: One character type: One boolean type: byte short int (most common) long
Primitive Types Four integer types: byte short int (most common) long Two floating-point types: float double (most common) One character type: char One boolean type: boolean 1 2 Primitive Types, cont.
More information5/3/2006. Today! HelloWorld in BlueJ. HelloWorld in BlueJ, Cont. HelloWorld in BlueJ, Cont. HelloWorld in BlueJ, Cont. HelloWorld in BlueJ, Cont.
Today! Build HelloWorld yourself in BlueJ and Eclipse. Look at all the Java keywords. Primitive Types. HelloWorld in BlueJ 1. Find BlueJ in the start menu, but start the Select VM program instead (you
More informationx = 3 * y + 1; // x becomes 3 * y + 1 a = b = 0; // multiple assignment: a and b both get the value 0
6 Statements 43 6 Statements The statements of C# do not differ very much from those of other programming languages. In addition to assignments and method calls there are various sorts of selections and
More informationAccount joeacct = new Account (100, new Account (500)); Account joeacct = new Account (100, new Account (500, null));
Exam information 369 students took the exam. Scores ranged from 1 to 20, with a median of 11 and an average of 11.1. There were 40 scores between 15.5 and 20, 180 between 10.5 and 15, 132 between 5.5 and
More information09/02/2013 TYPE CHECKING AND CASTING. Lecture 5 CS2110 Spring 2013
1 TYPE CHECKING AND CASTING Lecture 5 CS2110 Spring 2013 1 Type Checking 2 Java compiler checks to see if your code is legal Today: Explore how this works What is Java doing? Why What will Java do if it
More information1 Epic Test Review 2 Epic Test Review 3 Epic Test Review 4. Epic Test Review 5 Epic Test Review 6 Epic Test Review 7 Epic Test Review 8
Epic Test Review 1 Epic Test Review 2 Epic Test Review 3 Epic Test Review 4 Write a line of code that outputs the phase Hello World to the console without creating a new line character. System.out.print(
More informationCS5000: Foundations of Programming. Mingon Kang, PhD Computer Science, Kennesaw State University
CS5000: Foundations of Programming Mingon Kang, PhD Computer Science, Kennesaw State University Overview of Source Code Components Comments Library declaration Classes Functions Variables Comments Can
More informationChapter 2: Data and Expressions
Chapter 2: Data and Expressions CS 121 Department of Computer Science College of Engineering Boise State University August 21, 2017 Chapter 2: Data and Expressions CS 121 1 / 51 Chapter 1 Terminology Review
More informationOutline. Parts 1 to 3 introduce and sketch out the ideas of OOP. Part 5 deals with these ideas in closer detail.
OOP in Java 1 Outline 1. Getting started, primitive data types and control structures 2. Classes and objects 3. Extending classes 4. Using some standard packages 5. OOP revisited Parts 1 to 3 introduce
More informationThe for Loop. Lesson 11
The for Loop Lesson 11 Have you ever played Tetris? You know that the game never truly ends. Blocks continue to fall one at a time, increasing in speed as you go up in levels, until the game breaks from
More informationCIS October 16, 2018
CIS 1068 October 16, 2018 administrative stuff @@@ ADD ME @@@ Midterm Remember, the material is cumulative You ll see this stuff again Legal Identifiers c00lg33k is a legal identifier Legal Identifiers
More informationLexical Structure (Chapter 3, JLS)
Lecture Notes CS 140 Winter 2006 Craig A. Rich Lexical Structure (Chapter 3, JLS) - A Java source code file is viewed as a string of unicode characters, including line separators. - A Java source code
More informationprintf( Please enter another number: ); scanf( %d, &num2);
CIT 593 Intro to Computer Systems Lecture #13 (11/1/12) Now that we've looked at how an assembly language program runs on a computer, we're ready to move up a level and start working with more powerful
More informationJava Object Oriented Design. CSC207 Fall 2014
Java Object Oriented Design CSC207 Fall 2014 Design Problem Design an application where the user can draw different shapes Lines Circles Rectangles Just high level design, don t write any detailed code
More informationMODULE 02: BASIC COMPUTATION IN JAVA
MODULE 02: BASIC COMPUTATION IN JAVA Outline Variables Naming Conventions Data Types Primitive Data Types Review: int, double New: boolean, char The String Class Type Conversion Expressions Assignment
More informationJava Programming Fundamentals. Visit for more.
Chapter 4: Java Programming Fundamentals Informatics Practices Class XI (CBSE Board) Revised as per CBSE Curriculum 2015 Visit www.ip4you.blogspot.com for more. Authored By:- Rajesh Kumar Mishra, PGT (Comp.Sc.)
More informationChapter 2: Data and Expressions
Chapter 2: Data and Expressions CS 121 Department of Computer Science College of Engineering Boise State University January 15, 2015 Chapter 2: Data and Expressions CS 121 1 / 1 Chapter 2 Part 1: Data
More informationXC Total Max Score Grader
NAME: NETID: CS2110 Fall 2013, Prelim 1 Thursday Oct 10, 2013 (7:30-9:00p) The exam is closed book and closed notes. Do not begin until instructed. You have 90 minutes. Good luck! Write your name and Cornell
More informationQ1 Q2 Q3 Q4 Q5 Total 1 * 7 1 * 5 20 * * Final marks Marks First Question
Page 1 of 6 Template no.: A Course Name: Computer Programming1 Course ID: Exam Duration: 2 Hours Exam Time: Exam Date: Final Exam 1'st Semester Student no. in the list: Exam pages: Student's Name: Student
More informationCS4120/4121/5120/5121 Spring 2016 Xi Language Specification Cornell University Version of May 11, 2016
CS4120/4121/5120/5121 Spring 2016 Xi Language Specification Cornell University Version of May 11, 2016 In this course you will start by building a compiler for a language called Xi. This is an imperative,
More informationUNIT - I. Introduction to C Programming. BY A. Vijay Bharath
UNIT - I Introduction to C Programming Introduction to C C was originally developed in the year 1970s by Dennis Ritchie at Bell Laboratories, Inc. C is a general-purpose programming language. It has been
More informationJava Notes. 10th ICSE. Saravanan Ganesh
Java Notes 10th ICSE Saravanan Ganesh 13 Java Character Set Character set is a set of valid characters that a language can recognise A character represents any letter, digit or any other sign Java uses
More informationComputer Programming I - Unit 5 Lecture page 1 of 14
page 1 of 14 I. The while Statement while, for, do Loops Note: Loop - a control structure that causes a sequence of statement(s) to be executed repeatedly. The while statement is one of three looping statements
More informationJava Programming Basics. COMP 401, Spring 2017 Lecture 2
Java Programming Basics COMP 401, Spring 2017 Lecture 2 AverageHeightApp take 2 Same as before, but with Eclipse. Eclipse Workspace CreaJng new project CreaJng a new package CreaJng new class Running a
More informationLecture Set 4: More About Methods and More About Operators
Lecture Set 4: More About Methods and More About Operators Methods Definitions Invocations More arithmetic operators Operator Side effects Operator Precedence Short-circuiting main method public static
More informationPrinceton University. Computer Science 217: Introduction to Programming Systems. Data Types in C
Princeton University Computer Science 217: Introduction to Programming Systems Data Types in C 1 Goals of C Designers wanted C to: Support system programming Be low-level Be easy for people to handle But
More informationB.V. Patel Institute of BMC & IT, UTU 2014
BCA 3 rd Semester 030010301 - Java Programming Unit-1(Java Platform and Programming Elements) Q-1 Answer the following question in short. [1 Mark each] 1. Who is known as creator of JAVA? 2. Why do we
More informationJava Methods. Lecture 8 COP 3252 Summer May 23, 2017
Java Methods Lecture 8 COP 3252 Summer 2017 May 23, 2017 Java Methods In Java, the word method refers to the same kind of thing that the word function is used for in other languages. Specifically, a method
More informationImportant Java terminology
1 Important Java terminology The information we manage in a Java program is either represented as primitive data or as objects. Primitive data פרימיטיביים) (נתונים include common, fundamental values as
More informationExpressions and Data Types CSC 121 Spring 2017 Howard Rosenthal
Expressions and Data Types CSC 121 Spring 2017 Howard Rosenthal Lesson Goals Understand the basic constructs of a Java Program Understand how to use basic identifiers Understand simple Java data types
More informationData Types. 1 You cannot change the type of the variable after declaration. Zheng-Liang Lu Java Programming 52 / 87
Data Types Java is a strongly-typed 1 programming language. Every variable has a type. Also, every (mathematical) expression has a type. There are two categories of data types: primitive data types, and
More information2 nd Week Lecture Notes
2 nd Week Lecture Notes Scope of variables All the variables that we intend to use in a program must have been declared with its type specifier in an earlier point in the code, like we did in the previous
More informationChapter 6 Primitive types
Chapter 6 Primitive types Lesson page 6-1. Primitive types Question 1. There are an infinite number of integers, so it would be too ineffient to have a type integer that would contain all of them. Question
More informationCPS122 Lecture: From Python to Java last revised January 4, Objectives:
Objectives: CPS122 Lecture: From Python to Java last revised January 4, 2017 1. To introduce the notion of a compiled language 2. To introduce the notions of data type and a statically typed language 3.
More informationCS260 Intro to Java & Android 03.Java Language Basics
03.Java Language Basics http://www.tutorialspoint.com/java/index.htm CS260 - Intro to Java & Android 1 What is the distinction between fields and variables? Java has the following kinds of variables: Instance
More informationJava Identifiers, Data Types & Variables
Java Identifiers, Data Types & Variables 1. Java Identifiers: Identifiers are name given to a class, variable or a method. public class TestingShastra { //TestingShastra is an identifier for class char
More informationCS11 Java. Fall Lecture 1
CS11 Java Fall 2006-2007 Lecture 1 Welcome! 8 Lectures Slides posted on CS11 website http://www.cs.caltech.edu/courses/cs11 7-8 Lab Assignments Made available on Mondays Due one week later Monday, 12 noon
More informationGRAMMARS & PARSING. Lecture 7 CS2110 Fall 2013
1 GRAMMARS & PARSING Lecture 7 CS2110 Fall 2013 Pointers to the textbook 2 Parse trees: Text page 592 (23.34), Figure 23-31 Definition of Java Language, sometimes useful: http://docs.oracle.com/javase/specs/jls/se7/html/index.html
More informationCSc 10200! Introduction to Computing. Lecture 2-3 Edgardo Molina Fall 2013 City College of New York
CSc 10200! Introduction to Computing Lecture 2-3 Edgardo Molina Fall 2013 City College of New York 1 C++ for Engineers and Scientists Third Edition Chapter 2 Problem Solving Using C++ 2 Objectives In this
More informationCSE 1223: Introduction to Computer Programming in Java Chapter 2 Java Fundamentals
CSE 1223: Introduction to Computer Programming in Java Chapter 2 Java Fundamentals 1 Recall From Last Time: Java Program import java.util.scanner; public class EggBasketEnhanced { public static void main(string[]
More informationFull file at
Chapter 1 Primitive Java Weiss 4 th Edition Solutions to Exercises (US Version) 1.1 Key Concepts and How To Teach Them This chapter introduces primitive features of Java found in all languages such as
More informationCS/ENGRD 2110 SPRING 2018
CS/ENGRD 2110 SPRING 2018 Lecture 7: Interfaces and http://courses.cs.cornell.edu/cs2110 1 2 St Valentine s Day! It's Valentines Day, and so fine! Good wishes to you I consign.* But since you're my students,
More information1 class Lecture2 { 2 3 "Elementray Programming" / References 8 [1] Ch. 2 in YDL 9 [2] Ch. 2 and 3 in Sharan 10 [3] Ch.
1 class Lecture2 { 2 3 "Elementray Programming" 4 5 } 6 7 / References 8 [1] Ch. 2 in YDL 9 [2] Ch. 2 and 3 in Sharan 10 [3] Ch. 2 in HS 11 / Zheng-Liang Lu Java Programming 41 / 68 Example Given the radius
More informationWhat did we talk about last time? Examples switch statements
Week 4 - Friday What did we talk about last time? Examples switch statements History of computers Hardware Software development Basic Java syntax Output with System.out.print() Mechanical Calculation
More informationPeer Instruction 1. Elementary Programming
Peer Instruction 1 Elementary Programming 0 Which of the following variable declarations will not compile? Please select the single correct answer. A. int i = 778899; B. double x = 5.43212345; C. char
More informationHUDSONVILLE HIGH SCHOOL COURSE FRAMEWORK
HUDSONVILLE HIGH SCHOOL COURSE FRAMEWORK COURSE / SUBJECT Introduction to Programming KEY COURSE OBJECTIVES/ENDURING UNDERSTANDINGS OVERARCHING/ESSENTIAL SKILLS OR QUESTIONS Introduction to Java Java Essentials
More informationLoops. CSE 114, Computer Science 1 Stony Brook University
Loops CSE 114, Computer Science 1 Stony Brook University http://www.cs.stonybrook.edu/~cse114 1 Motivation Suppose that you need to print a string (e.g., "Welcome to Java!") a user-defined times N: N?
More informationEXPRESSIONS AND ASSIGNMENT CITS1001
EXPRESSIONS AND ASSIGNMENT CITS1001 Scope of this lecture Assignment statements Expressions ASSIGNMENT STATEMENT Assignment Statements!!!mark = 50;!! Read as the value in variable on the LHS becomes equal
More informationCOMP 250: Java Programming I. Carlos G. Oliver, Jérôme Waldispühl January 17-18, 2018 Slides adapted from M. Blanchette
COMP 250: Java Programming I Carlos G. Oliver, Jérôme Waldispühl January 17-18, 2018 Slides adapted from M. Blanchette Variables and types [Downey Ch 2] Variable: temporary storage location in memory.
More information