CS Exam 2 Study Guide and Practice Exam
|
|
- Alaina Russell
- 6 years ago
- Views:
Transcription
1 CS Exam 2 Study Guide and Practice Exam March 28, 2016 Summary 1 Disclaimer 2 Loops 2.1 For loops While loops Do-While Loops Hints and Warnings Methods 3.1 Static vs. Non-Static Return Values Parameters Pass-by-Reference vs Pass-by-Value Examples Arrays 4.1 Basics Warnings Discrete Math 5.1 Propositional Logic Practice Written Exam 6.1 Short Answer Tracing Code Programming Quiz Practice Exam 8 Suggestions for Studying and Test Taking 8.1 Written Programming Quiz Challenges
2 1 Disclaimer This is a review of the material so far, but there may be material on the exam not covered in this study guide. 2 Loops 2.1 For loops For loops are used when you know how many iterations the loop needs to complete. General syntax: for ( int i = 0; i < somelength; i++){ //some code You can also think of for loops as such: for (initialization; range; update) { //some code Real life example : A loop used print every second letter backwards (z, x, v, t...). for ( char c = z ; c >= a ; c-=2){ System.out.print(c); 2.2 While loops While loops are generally used when you don t know how many iterations you need the loop to complete (i.e. if you are reading entered words from the keyboard until the user types stop ). General syntax: int i = 0; while (i < somelength){ //some code i++; You can also think of for loops as such: initialization; //outside of loop while (range){ //some code update Same Real life example as above. char c = z ; while (c >= a ){ System.out.print(c); c-=2; 2.3 Do-While Loops Do-While loops are used when you want the loop to run at least once, regardless of whether the value is in the range. General syntax:
3 int i = 0; do { //code i++; while (range); Same Real life example as from before. char c = z ; do { System.out.print(c); c-=2; while (c >= a ); 2.4 Hints and Warnings Warning: Watch the ranges! For an array of size 8, i < 9 is the same as i apple 8 (which would iterate over all of the values in the array). However, i apple 9 will give you an Index Out Of Bounds Exception. Hint: You can always change your update by using the += or -= method, especially if you are updating by more than 1. Hint: You can always change your starting point, you don t have to start at 0, it is just the most common. If you were asked to reverse a string, you can always make the starting point at stringname.length-1! (Remember the -1 though, lengths are 1 based while loops are 0 based usually). Summary: Basically you can solve a problem with loops in many di erent ways whether it s using a di erent loop, starting at a di erent place, changing your ending value, or changing how you update. 3 Methods 3.1 Static vs. Non-Static Static methods are used when you used when you aren t going to use instance variables. To call a static method that you ve made: public static void main (String [] args){ int mycoolandcleverintegername = 0; printmyinteger(mycoolandcleverintegername); //prints 0 public static void printmyinteger(int i){ System.out.println(i); //it s a cool method, I know :) To call a static method from a di erent class: public static void main (String [] args){ int mynumber = 10; // Math is the class, pow is the static method int mynumbersquared = Math.pow(myNumber,2); System.out.printf("my number: %d, my number squared: %d", mynumber, mynumbersquared);
4 Non-static methods use instance variables. To call a non-static method: public class Exam2 { private int mycoolandcleverintegername = 0; public static void main (String [] args){ Exam2 exam = new Exam2 (); /* because mycoolandcleverintegername is * an instance variable it can be used in * ANY method in this class. */ exam.printmyinteger(); //prints 0 public void printmyinteger(){ System.out.println(myCoolandCleverIntegerName); 3.2 Return Values When a method has a return value of void it returns no value. You can print or manipulate instance variables and objects, without using the return keyword. When a method has a return value of double, int, String, String [ ], etc you must return a value of that type. For example, public int multiply(int a, int b) must return an integer or public String [] toarray(string s) must return a String array. 3.3 Parameters Parameters are values that are passed in through the method when it is called. These are variables that you can use and manipulate (BEWARE of pass-by-reference and pass-by-value!). Given the following code, notice that we passed the multiply method myint and mydouble but we used the variables i and d. This is where the warning comes in, this does not change any value. In order for the values to be changed in the main method we would need to assign. Also, when you call multiply(myint,mydouble);, you need to use a println or store the value in a variable and then print it for anything to be shown in the console. public static void main (String [] args0){ int myint = 3; double mydouble = 4.0; // will this do anything? multiply(myint, mydouble); public static double multiply(int i, double d){ double result = i * d; return result; Pass-by-Reference vs Pass-by-Value Pass-by-Reference are usually objects. This is because they have their own specified memory (aka it has memory allocated for the variable), so when a method calls that variable it accesses that place in memory and manipulates that. Therefore, Pass-by-Reference variables ARE CHANGED! For example:
5 public static void main (String [] args0){ int [] intarray = {1, 2, 3; System.out.println(Arrays.toString(multiplyIndex0(intArray,9))); //prints [9,2,3] System.out.println(Arrays.toString(intArray)); //prints [9,2,3] public static int [] multiplyindex0(int [] i, int p){ i[0] = p; return i; Pass-by-Value are primitive types that are passed into a method s parameter. THESE VALUES ARE NOT CHANGED OUTSIDE THE METHOD THAT INITIALIZES THEM. The calling method creates a copy of the values so the original values are never changed. For example: //method that is calling ( aka caller method) public static void main (String [] args0) { int number = 100; increment(number); System.out.println("Number: " + number); //method being called ( aka calling method) public static void increment(int n){ n++; //NUMBER IS NEVER CHANGED 3.4 Examples public class PsuedoString{ char [] greeting = { H, e, l, l, o ; //the charat String method public char charat(int index){ //must return a char return greeting[index]; //calling the non- static method public static void main(string [] args){ Psuedo p = new Pseudo(); p.charat(someinteger); public class Practice{ //a static method that makes a string from 3 characters public static String chartostring(char a, char b, char c){ String string1 = Character.toString(a) + Character.toString(b) + Character.toString(c); return string1;
6 //a method that prints a String array s elements public static void printarray (String [] sarray) { for ( int i = 0; i < sarray.length; i++) System.out.print(sArray[i] + " "); public static void main (String [] args){ String [] arr = {" Twas", "the", "night", "before", "my", "CS 160", "Exam.", " Twas", "a", "dark", "stormy", "night", "without", "a", "soul", "in sight", "..."; 4 Arrays 4.1 Basics printarray(arr); String newstring = chartostring( h, i,! ); System.out.println(newString); //two ways to initialize an array //you know only the size typeofarray [] nameofarray = new typeofarray [sizeofarray]; //you know what the values are typeofarray [] nameofarray1 = {values, you, want, in, the, array; Some Basics: To print you either need to make a loop or usearrays.tostring(). for ( int i = 0; i < arrayname.length; i++){ //Notice the lack of parenthesis after length! System.out.print(arrayName[i]); //Read directions carefully, you may need to add a space, an underscore, hyphen, semicolon, etc to the string. System.out.println(Arrays.toString(arrayName)); To manipulate the array String [] sarray = new String [3]; // to change on value in the array sarray[0] = "Hola"; // to find the length of a string int [] iarray = {1, 1, 1, 1, 1, 0; //remember there are no parenthesis after length like there is with Strings. System.out.println(iArray.length);
7 Multi-Dimensional Arrays // Initialization int [][] array = {{1,2,3,{1,2,3; // Printing a 2D Array for ( int row = 0; row < array.length; row++){ for ( int col = 0; col < array[row].length; col++){ // prints the value at array[ row][col] followed // by a comma then a space. System.out.print(array[row][col] + ", "); 2D Arrays are like tables, the first [ ] represent the rows and the second [ ] represent the columns. 4.2 Warnings Warning: Remember the length method starts at 1 and index starts at 0. If you had an array of length 3 and you try to change the value at arrayname[3] you will get an IndexOutOfBoundsException. Warning: Remember that you don t add ( ) to the length method. It is just arrayname.length. Warning: Arrays are objects, regardless if the type of array is a primitive type. So you can t use == on an array YOU MUST USE THE.EQUALS METHOD! 5 Discrete Math 5.1 Propositional Logic This is not comprehensive. Tautology: a proposition that is always true Contradiction: a proposition that is always false Contingency: a proposition that is neither always true and neither false (aka neither a tautology nor a contradiction) Given p! q Converse: q! p - Reverse the order Inverse: p! q - Negate the original order Contrapositive: q! p - Negate and reverse the order.
8 6 Practice Written Exam If you would like practice in Discrete Math: go to the CS 160 Homepage and under the Tutorials tab there are practice quizzes. 6.1 Short Answer 1. Declare an integer array name myintarray that contains 3 elements. 2. Use a for loop to assign the value 1 to every element in myintarray. 3. Change the last element in myintarray to 99, don t hard code. 4. Create a double 2D array called darray with 3x3 elements. Challenge: Create a double 2D array called darray initialized to the values {1.0, 2.0, 3.0 and {4.0, 5.0, 6.0, 7.0. (Note: 2D arrays can have di erent sizes for each row or column(in this example row 0 is length of 3 and row 1 is length of 4.)) 5. Declare the header to a public, static method that s called printer, it takes an integer as a parameter, returns nothing. 6. Declare a public method called multiplier that has two integers as parameters and it returns a double of the two integers. Call this method (which is in a class called Multiplier in your main with the integers 3 and Write a for loop, while loop, and do-while loop that prints odd numbers from 1 to 101 all on one line. 8. Declare a public, static method called find that has a String and character parameter. This method s purpose is to count the number of times a character is in the given string. find returns the count. Call this method (in your main method), with a stereos are as good as oreos and a character of o. 9. Write a method that is public, non-static, called toascii which has a String parameter, and returns an integer array. This method takes each letter in the String and converts the characters into Ascii values and places each character into a di erent element of an integer array (with the same order as the string). 6.2 Tracing Code /* Instructions: * By each commented number write down what the console would print. * There are some questions that return errors. Either write " error" or you can write the exception name. * If you find an infinite loop. Continue through the questions( even though the rest of the program would never print. * Write " infinite loop" for those cases for the questions. * */ import java.util.arrays; public class Trace { private int[] iflip; private String concat = ""; public int[] flip(int [] iarray){ iflip = new int [iarray.length]; for ( int i = iarray.length-1; i >= 0; i--) iflip[i] = iarray[i]; return iflip; public static double[] update(double[] d){ for ( int i = 0; i < d.length; i++){ d[i] = 1; return d;
9 public static void printshift (char c){ System.out.print("Shifted right 2 characters from " + c + " to "); c+=2; System.out.println(c); public int increment (int i){ return i++; public void makestring(string [] stringarray){ for ( int i = 0; i < stringarray.length; i++) concat += stringarray[i]; return concat; public void arrayprinter(){ for ( int i = 0; i < iflip.length; i++) System.out.print(iFlip[i]); public static void main (String [] args){ Trace trace = new Trace(); int [] integerarray = {1, 2, 3; int [] secondintarray = {4, 5, 6, 7, 8, 9, 10; double [] darray = {1.0, 22.0, 333.0, ; String [] badnamemashups = {"Bobbylene", "Jimmeroo", "Samandra", "Georgina", "Henrietta"; String [] boringstringarray = {"I am", "a", "boring", "string"; int counter = 0; char c = a ; //Question 1: What does the console print EXACTLY for ( int i = 0; i < 30; i++){ if (i % 3 == 0){ System.out.print(i + ", "); System.out.println(); int usernum = 3; //Question 2: Does this print anything? If not write " none", if it does write what s printed do { System.out.println("The usernum value is: " + usernum); while (usernum > 5); //Question 3: for ( int i = 0; i < integerarray.length; i++) System.out.print(integerArray[i]); System.out.println();
10 //Question 4: System.out.println( Arrays.toString(trace.flip(integerArray))); update(darray); //Question 5: System.out.println(Arrays.toString(dArray)); darray[4] = -2.0; //Question 6: System.out.println(dArray[4]); //Question 7: while (counter >= 0){ System.out.print(counter); trace.increment(counter); //Question 8: printshift(c); //Question 9: System.out.println(c); //Question 10: for ( int i = 0; i <= badnamemashups.length; i++){ System.out.print(badNameMashUps[i] + " & "); //Question 11: trace.makestring(boringstringarray); //Question 12: arrayprinter(secondintarray); 7 Programming Quiz Practice Exam Instructions: Your program must have only 11 lines of output. If you don t know how to solve one of the question print an empty line so you get credit for the rest of the quiz. 1. Make a public, non-static method that takes a parameter of one String array, returns a String of every other letter in each string in the string array (include spaces), call the method everyother. 2. Make a public, static method called info that when given a String (as a parameter) the method prints the length of the the String, the first and last character, and it prints the index of a, if it does not have an a in the string it returns -1. Do not make another String variable to copy/edit, use the parameter. (returns nothing, everything is on di erent lines) 3. Create a private instance variable of type String, called personalitystring. Write a public, non-static method, called personality, this method will use the personalitystring (hint: don t use a parameter) and returns another String. Use a conditional statement of your choice to return your String. If the parameter String has a length of less than or equal to 3, return silent, if it has a length between 4 and inclusively 9, return smarty, if the length is more than 9 then return talker. Inside your main method: 4. Make a String array called sarray and assign Hola, Hi there, Hello, and Sup. Use this to test
11 question Make a String variable called s1 and assign supercalifragilisticexpialidocious to it (fun fact: this is 5th longest English word, exciting I know). Use this to test question Make four String variables called s2, s3, s4, 25 and use these variables to test the method from question Make a 2D int array called iarray2d, that is a 4x4 box. 8. Initialize all values in the array to 42 (because it s the answer to everything). 9. Print out the 2D array s values with commas separating the values, all on one line. (Expect a trailing comma) 10. Make a double array called doublearray and initialize the array to the values 1.0, 2.0, 3.0, 4.0, 5.0, and Print the 3rd value in doublearray. 8 Suggestions for Studying and Test Taking 8.1 Written Write down for, while, do-while loops/templates. Know what each piece does, that way when you come across a problem that needs a loop then you can quickly change a piece (initialization/starting point, range, or ending place) of the loop to solve your problem. Practice writing code in Eclipse and before you run your program guess what the output would be. is good practice for testing your own programs and also for the code tracing part of the exam. This For your discrete math there are interactive quizzes under the Tutorials tab on the CS 160 Homepage. 8.2 Programming Quiz Go back to past recitations and assignments and redo them without using the internet, friends, or past recitations/assignments. Practice writing code in Eclipse. Make up projects and problems or ask a TA and they can give you some challenges. Look at code, the more exposure you get to code (whether it s your own code or not) the easier it is to understand. Under the Progress Page many of the units have programs that you can look at. 8.3 Challenges Create a method that reverses a string array. There are some cool rhymes/poems that make sense forward and backwards. You can also make this into an array challenge by separating the poem/rhyme by words and putting each word into a di erent element of a String array. Then reverse that. Under the Resources tab on the CS 160 Homepage there are some coding practice sites, like CodingBat.
CS 163/164 - Exam 2 Study Guide and Practice Written Exam
CS 163/164 - Exam 2 Study Guide and Practice Written Exam October 22, 2016 Summary 1 Disclaimer 2 Methods and Data 2.1 Static vs. Non-Static........................................... 2.2 Static...................................................
More informationObject-Oriented Programming
Object-Oriented Programming Java Syntax Program Structure Variables and basic data types. Industry standard naming conventions. Java syntax and coding conventions If Then Else Case statements Looping (for,
More informationLast Class. More on loops break continue A bit on arrays
Last Class More on loops break continue A bit on arrays public class February2{ public static void main(string[] args) { String[] allsubjects = { ReviewArray, Example + arrays, obo errors, 2darrays };
More informationPace University. Fundamental Concepts of CS121 1
Pace University Fundamental Concepts of CS121 1 Dr. Lixin Tao http://csis.pace.edu/~lixin Computer Science Department Pace University October 12, 2005 This document complements my tutorial Introduction
More informationLast Class. While loops Infinite loops Loop counters Iterations
Last Class While loops Infinite loops Loop counters Iterations public class January31{ public static void main(string[] args) { while (true) { forloops(); if (checkclassunderstands() ) { break; } teacharrays();
More informationBuilding Java Programs Chapter 2
Building Java Programs Chapter 2 Primitive Data and Definite Loops Copyright (c) Pearson 2013. All rights reserved. Data types type: A category or set of data values. Constrains the operations that can
More informationBuilding Java Programs Chapter 2. bug. Primitive Data and Definite Loops. Copyright (c) Pearson All rights reserved. Software Flaw.
Building Java Programs Chapter 2 bug Primitive Data and Definite Loops Copyright (c) Pearson 2013. All rights reserved. 2 An Insect Software Flaw 3 4 Bug, Kentucky Bug Eyed 5 Cheesy Movie 6 Punch Buggy
More informationBuilding Java Programs Chapter 2
Building Java Programs Chapter 2 Primitive Data and Definite Loops Copyright (c) Pearson 2013. All rights reserved. bug 2 An Insect 3 Software Flaw 4 Bug, Kentucky 5 Bug Eyed 6 Cheesy Movie 7 Punch Buggy
More informationChapter 6 SINGLE-DIMENSIONAL ARRAYS
Chapter 6 SINGLE-DIMENSIONAL ARRAYS Lecture notes for computer programming 1 Faculty of Engineering and Information Technology Prepared by: Iyad Albayouk What is an Array? A single array variable can reference
More informationCourse Outline. Introduction to java
Course Outline 1. Introduction to OO programming 2. Language Basics Syntax and Semantics 3. Algorithms, stepwise refinements. 4. Quiz/Assignment ( 5. Repetitions (for loops) 6. Writing simple classes 7.
More informationCS 112 Introduction to Computing II. Wayne Snyder Computer Science Department Boston University
9/5/6 CS Introduction to Computing II Wayne Snyder Department Boston University Today: Arrays (D and D) Methods Program structure Fields vs local variables Next time: Program structure continued: Classes
More information13 th Windsor Regional Secondary School Computer Programming Competition
SCHOOL OF COMPUTER SCIENCE 13 th Windsor Regional Secondary School Computer Programming Competition Hosted by The School of Computer Science, University of Windsor WORKSHOP I [ Overview of the Java/Eclipse
More informationProgramming with Java
Programming with Java Variables and Output Statement Lecture 03 First stage Software Engineering Dep. Saman M. Omer 2017-2018 Objectives ü Declare and assign values to variable ü How to use eclipse ü What
More informationGetting started with Java
Getting started with Java Magic Lines public class MagicLines { public static void main(string[] args) { } } Comments Comments are lines in your code that get ignored during execution. Good for leaving
More informationComputer Science is...
Computer Science is... Machine Learning Machine learning is the study of computer algorithms that improve automatically through experience. Example: develop adaptive strategies for the control of epileptic
More informationCOMP-202 Unit 4: Programming With Iterations. CONTENTS: The while and for statements
COMP-202 Unit 4: Programming With Iterations CONTENTS: The while and for statements Introduction (1) Suppose we want to write a program to be used in cash registers in stores to compute the amount of money
More informationCS 163/164 Exam 2 Review
CS 163/164 Exam 2 Review Review from first exam What does this print? String s = marco polo ; System.out.println(s.substring(0,3)); mar Print the predefined double variable d with 9 decimal place precision
More informationLecture 17. Instructor: Craig Duckett. Passing & Returning Arrays
Lecture 17 Instructor: Craig Duckett Passing & Returning Arrays Assignment Dates (By Due Date) Assignment 1 (LECTURE 5) GRADED! Section 1: Monday, January 22 nd Assignment 2 (LECTURE 8) GRADED! Section
More informationCOMP-202: Foundations of Programming. Lecture 4: Flow Control Loops Sandeep Manjanna, Summer 2015
COMP-202: Foundations of Programming Lecture 4: Flow Control Loops Sandeep Manjanna, Summer 2015 Announcements Check the calendar on the course webpage regularly for updates on tutorials and office hours.
More informationLec 7. for loops and methods
Lec 7 for loops and methods Announcements Quiz 1 on Friday Review today. 5:00. CENTR 212 Assume there s a method drawrandomfruit() How would you create this: While loops final int DIMENSION = 9; int row
More informationChapter 5 Control Statements: Part 2 Section 5.2 Essentials of Counter-Controlled Repetition
Chapter 5 Control Statements: Part 2 Section 5.2 Essentials of Counter-Controlled Repetition 5.2 Q1: Counter-controlled repetition requires a. A control variable and initial value. b. A control variable
More informationLast Class. Introduction to arrays Array indices Initializer lists Making an array when you don't know how many values are in it
Last Class Introduction to arrays Array indices Initializer lists Making an array when you don't know how many values are in it public class February4{ public static void main(string[] args) { String[]
More informationCOMP 401 Midterm. Tuesday, Oct 18, pm-3:15pm. Instructions
COMP 401 Midterm Tuesday, Oct 18, 2016 2pm-3:15pm Instructions 1. Please spread out and try and sit in alternate seats. 2. This is a closed book exam. 3. You will not be penalized for errors in Java syntax.
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 informationQUIZ: What value is stored in a after this
QUIZ: What value is stored in a after this statement is executed? Why? a = 23/7; QUIZ evaluates to 16. Lesson 4 Statements, Expressions, Operators Statement = complete instruction that directs the computer
More informationIntroduction to Java & Fundamental Data Types
Introduction to Java & Fundamental Data Types LECTURER: ATHENA TOUMBOURI How to Create a New Java Project in Eclipse Eclipse is one of the most popular development environments for Java, as it contains
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 informationWentworth Institute of Technology. Engineering & Technology WIT COMP1000. Java Basics
WIT COMP1000 Java Basics Java Origins Java was developed by James Gosling at Sun Microsystems in the early 1990s It was derived largely from the C++ programming language with several enhancements Java
More informationarray Indexed same type
ARRAYS Spring 2019 ARRAY BASICS An array is an indexed collection of data elements of the same type Indexed means that the elements are numbered (starting at 0) The restriction of the same type is important,
More informationCS 231 Data Structures and Algorithms, Fall 2016
CS 231 Data Structures and Algorithms, Fall 2016 Dr. Bruce A. Maxwell Department of Computer Science Colby College Course Description Focuses on the common structures used to store data and the standard
More informationCSE 20. SAMPLE FINAL Version A Time: 180 minutes. The following precedence table is provided for your use:
CSE 20 SAMPLE FINAL Version A Time: 180 minutes Name The following precedence table is provided for your use: Precedence of Operators ( ) - (unary),!, ++, -- *, /, % +, - (binary) = = =,!= &&
More informationThe Warhol Language Reference Manual
The Warhol Language Reference Manual Martina Atabong maa2247 Charvinia Neblett cdn2118 Samuel Nnodim son2105 Catherine Wes ciw2109 Sarina Xie sx2166 Introduction Warhol is a functional and imperative programming
More informationIntroduction to the Java Basics: Control Flow Statements
Lesson 3: Introduction to the Java Basics: Control Flow Statements Repetition Structures THEORY Variable Assignment You can only assign a value to a variable that is consistent with the variable s declared
More informationCS201- Introduction to Programming Current Quizzes
CS201- Introduction to Programming Current Quizzes Q.1 char name [] = Hello World ; In the above statement, a memory of characters will be allocated 13 11 12 (Ans) Q.2 A function is a block of statements
More informationFall 2017 CISC124 9/16/2017
CISC124 Labs start this week in JEFF 155: Meet your TA. Check out the course web site, if you have not already done so. Watch lecture videos if you need to review anything we have already done. Problems
More informationBASIC COMPUTATION. public static void main(string [] args) Fundamentals of Computer Science I
BASIC COMPUTATION x public static void main(string [] args) Fundamentals of Computer Science I Outline Using Eclipse Data Types Variables Primitive and Class Data Types Expressions Declaration Assignment
More informationFinal Exam. COMP Summer I June 26, points
Final Exam COMP 14-090 Summer I 2000 June 26, 2000 200 points 1. Closed book and closed notes. No outside material allowed. 2. Write all answers on the test itself. Do not write any answers in a blue book
More informationTerm 1 Unit 1 Week 1 Worksheet: Output Solution
4 Term 1 Unit 1 Week 1 Worksheet: Output Solution Consider the following what is output? 1. System.out.println("hot"); System.out.println("dog"); Output hot dog 2. System.out.print("hot\n\t\t"); System.out.println("dog");
More informationBuilding Java Programs
Building Java Programs Chapter 2 Lecture 2-1: Expressions and Variables reading: 2.1-2.2 1 2 Data and expressions reading: 2.1 3 The computer s view Internally, computers store everything as 1 s and 0
More informationCOSC 236 Section 101 Computer Science 1 -- Prof. Michael A. Soderstrand
COSC 236 Section 101 Computer Science 1 -- Prof. Michael A. Soderstrand COSC 236 Web Site I have decided to keep this site for the whole semester I still hope to have blackboard up and running, but you
More informationCS111: PROGRAMMING LANGUAGE II
1 CS111: PROGRAMMING LANGUAGE II Computer Science Department Lecture 1: Introduction Lecture Contents 2 Course info Why programming?? Why Java?? Write once, run anywhere!! Java basics Input/output Variables
More informationExample: Computing prime numbers
Example: Computing prime numbers -Write a program that lists all of the prime numbers from 1 to 10,000. Remember a prime number is a # that is divisible only by 1 and itself Suggestion: It probably will
More informationChapter 4 Control Structures
Chapter 4 Control Structures Foundational Java Key Elements and Practical Programming 1 if - else switch Control Structures break and continue Ternary operator while and do-while loops for loops 2 Two
More informationMethods and Data (Savitch, Chapter 5)
Methods and Data (Savitch, Chapter 5) TOPICS Invoking Methods Return Values Local Variables Method Parameters Public versus Private 2 public class Temperature { public static void main(string[] args) {
More informationBuilding Java Programs
Building Java Programs Chapter 2 Lecture 2-1: Expressions and Variables reading: 2.1-2.2 1 Data and expressions reading: 2.1 self-check: 1-4 videos: Ch. 2 #1 2 Data types type: A category or set of data
More informationCS201- Introduction to Programming Latest Solved Mcqs from Midterm Papers May 07,2011. MIDTERM EXAMINATION Spring 2010
CS201- Introduction to Programming Latest Solved Mcqs from Midterm Papers May 07,2011 Lectures 1-22 Moaaz Siddiq Asad Ali Latest Mcqs MIDTERM EXAMINATION Spring 2010 Question No: 1 ( Marks: 1 ) - Please
More informationTOPIC 2 INTRODUCTION TO JAVA AND DR JAVA
1 TOPIC 2 INTRODUCTION TO JAVA AND DR JAVA Notes adapted from Introduction to Computing and Programming with Java: A Multimedia Approach by M. Guzdial and B. Ericson, and instructor materials prepared
More informationCOMP-202: Foundations of Programming. Lecture 2: Variables, and Data Types Sandeep Manjanna, Summer 2015
COMP-202: Foundations of Programming Lecture 2: Variables, and Data Types Sandeep Manjanna, Summer 2015 Announcements Midterm Exams on 4 th of June (12:35 14:35) Room allocation will be announced soon
More informationBuilding Java Programs
Building Java Programs Chapter 2 Lecture 2-1: Expressions and Variables reading: 2.1-2.2 Copyright 2009 by Pearson Education Data and expressions reading: 2.1 self-check: 1-4 videos: Ch. 2 #1 Copyright
More informationCHAPTER 7 ARRAYS: SETS OF SIMILAR DATA ITEMS
CHAPTER 7 ARRAYS: SETS OF SIMILAR DATA ITEMS Computers process information and usually they need to process masses of information. In previous chapters we have studied programs that contain a few variables
More informationInterpreted vs Compiled. Java Compile. Classes, Objects, and Methods. Hello World 10/6/2016. Python Interpreted. Java Compiled
Interpreted vs Compiled Python 1 Java Interpreted Easy to run and test Quicker prototyping Program runs slower Compiled Execution time faster Virtual Machine compiled code portable Java Compile > javac
More informationCS 101 Spring 2007 Midterm 2 Name: ID:
You only need to write your name and e-mail ID on the first page. This exam is CLOSED text book, closed-notes, closed-calculator, closed-neighbor, etc. Questions are worth different amounts, so be sure
More informationCS Programming I: Primitives and Expressions
CS 200 - Programming I: Primitives and Expressions Marc Renault Department of Computer Sciences University of Wisconsin Madison Spring 2018 TopHat Sec 3 (AM) Join Code: 427811 TopHat Sec 4 (PM) Join Code:
More informationPractice exam for CMSC131-04, Fall 2017
Practice exam for CMSC131-04, Fall 2017 Q1 makepalindrome - Relevant topics: arrays, loops Write a method makepalidrome that takes an int array, return a new int array that contains the values from the
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 informationMr. Monroe s Guide to Mastering Java Syntax
Mr. Monroe s Guide to Mastering Java Syntax Getting Started with Java 1. Download and install the official JDK (Java Development Kit). 2. Download an IDE (Integrated Development Environment), like BlueJ.
More informationArrays. Eng. Mohammed Abdualal
Islamic University of Gaza Faculty of Engineering Computer Engineering Department Computer Programming Lab (ECOM 2114) Created by Eng: Mohammed Alokshiya Modified by Eng: Mohammed Abdualal Lab 9 Arrays
More informationFinal Exam CS 152, Computer Programming Fundamentals December 9, 2016
Final Exam CS 152, Computer Programming Fundamentals December 9, 2016 Name: NetID: Answer all questions in the space provided. Write clearly and legibly, you will not get credit for illegible or incomprehensible
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 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 informationLast Time. University of British Columbia CPSC 111, Intro to Computation Alan J. Hu. Readings
University of British Columbia CPSC 111, Intro to Computation Alan J. Hu Writing a Simple Java Program Intro to Variables Readings Your textbook is Big Java (3rd Ed). This Week s Reading: Ch 2.1-2.5, Ch
More informationJava Basic Programming Constructs
Java Basic Programming Constructs /* * This is your first java program. */ class HelloWorld{ public static void main(string[] args){ System.out.println( Hello World! ); A Closer Look at HelloWorld 2 This
More informationCSCE 145 Exam 1 Review Answers. This exam totals to 100 points. Follow the instructions. Good luck!
CSCE 145 Exam 1 Review Answers This exam totals to 100 points. Follow the instructions. Good luck! Chapter 1 This chapter was mostly terms so expect a fill in the blank style questions on definition. Remember
More informationArrays Data structures Related data items of same type Remain same size once created Fixed-length entries
CBOP3203 Arrays Data structures Related data items of same type Remain same size once created Fixed-length entries A 12 element Array Index Also called subscript Position number in square brackets Must
More informationCS 163/164 Exam 2 Review
CS 163/164 Exam 2 Review Review from first exam What does this print? String s = marco polo ; System.out.println(s.substring(0,3)); mar Print the predefined double variable d with 9 decimal place precision
More informationCS201 Latest Solved MCQs
Quiz Start Time: 09:34 PM Time Left 82 sec(s) Question # 1 of 10 ( Start time: 09:34:54 PM ) Total Marks: 1 While developing a program; should we think about the user interface? //handouts main reusability
More informationFaculty of Science COMP-202A - Introduction to Computing I (Fall 2008) Midterm Examination
First Name: Last Name: McGill ID: Section: Faculty of Science COMP-202A - Introduction to Computing I (Fall 2008) Midterm Examination Tuesday, November 4, 2008 Examiners: Mathieu Petitpas [Section 1] 18:30
More informationReview. Primitive Data Types & Variables. String Mathematical operators: + - * / % Comparison: < > <= >= == int, long float, double boolean char
Review Primitive Data Types & Variables int, long float, double boolean char String Mathematical operators: + - * / % Comparison: < > = == 1 1.3 Conditionals and Loops Introduction to Programming in
More informationCenter for Computation & Louisiana State University -
Knowing this is Required Anatomy of a class A java program may start with import statements, e.g. import java.util.arrays. A java program contains a class definition. This includes the word "class" followed
More informationECE 122. Engineering Problem Solving with Java
ECE 122 Engineering Problem Solving with Java Lecture 10 For Loops and Arrays Outline Problem: How can I perform the same operations a fixed number of times? Considering for loops Performs same operations
More informationBasic computer skills such as using Windows, Internet Explorer, and Microsoft Word. Chapter 1 Introduction to Computers, Programs, and Java
Basic computer skills such as using Windows, Internet Explorer, and Microsoft Word Chapter 1 Introduction to Computers, Programs, and Java Chapter 2 Primitive Data Types and Operations Chapter 3 Selection
More informationMethods. Methods. Mysteries Revealed
Methods Methods and Data (Savitch, Chapter 5) TOPICS Invoking Methods Return Values Local Variables Method Parameters Public versus Private A method (a.k.a. func2on, procedure, rou2ne) is a piece of code
More informationChapter 7. Iteration. 7.1 Multiple assignment
Chapter 7 Iteration 7.1 Multiple assignment You can make more than one assignment to the same variable; effect is to replace the old value with the new. int bob = 5; System.out.print(bob); bob = 7; System.out.println(bob);
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 information1.00 Tutorial 1. Introduction to 1.00
1.00 Tutorial 1 Introduction to 1.00 Outline Introductions Administrative Stuff PS 0 Java Basics Eclipse practice PS1 discussion Administrative stuff (1) Top five reasons why you should attend tutorials:
More informationDefinite Loops. Computer Science S-111 Harvard University David G. Sullivan, Ph.D. Using a Variable for Counting
Unit 2, Part 2 Definite Loops Computer Science S-111 Harvard University David G. Sullivan, Ph.D. Using a Variable for Counting Let's say that we're using a variable i to count the number of times that
More informationCoding Standards for Java
Why have coding standards? Coding Standards for Java Version 1.3 It is a known fact that 80% of the lifetime cost of a piece of software goes to maintenance; therefore, it makes sense for all programs
More informationCS 170 Exam 2. Version: A Fall Name (as in OPUS) (print): Instructions:
CS 170 Exam 2 Version: A Fall 2015 Name (as in OPUS) (print): Section: Seat Assignment: Instructions: Keep your eyes on your own paper and do your best to prevent anyone else from seeing your work. Do
More informationGrouping Objects. Primitive Arrays and Iteration. Produced by: Dr. Siobhán Drohan. Department of Computing and Mathematics
Grouping Objects Primitive Arrays and Iteration Produced by: Dr. Siobhán Drohan Department of Computing and Mathematics http://www.wit.ie/ Topic List Primitive arrays Why do we need them? What are they?
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 informationCIS Introduction to Computer Programming Spring Exam 1
CIS 110 - Introduction to Computer Programming Spring 2017 - Exam 1 Name: Recitation (e.g. 201): PennKey (e.g. eeaton): My signature below certifies that I have complied with the University of Pennsylvania
More informationCS112 Lecture: Variables, Expressions, Computation, Constants, Numeric Input-Output
CS112 Lecture: Variables, Expressions, Computation, Constants, Numeric Input-Output Last revised January 12, 2006 Objectives: 1. To introduce arithmetic operators and expressions 2. To introduce variables
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 informationRepetition, Looping. While Loop
Repetition, Looping Last time we looked at how to use if-then statements to control the flow of a program. In this section we will look at different ways to repeat blocks of statements. Such repetitions
More informationDeclaring and ini,alizing 2D arrays
Declaring and ini,alizing 2D arrays 4 2D Arrays (Savitch, Chapter 7.5) TOPICS Multidimensional Arrays 2D Array Allocation 2D Array Initialization TicTacToe Game // se2ng up a 2D array final int M=3, N=4;
More informationLanguage Reference Manual
ALACS Language Reference Manual Manager: Gabriel Lopez (gal2129) Language Guru: Gabriel Kramer-Garcia (glk2110) System Architect: Candace Johnson (crj2121) Tester: Terence Jacobs (tj2316) Table of Contents
More informationCS163/164 Final Exam Study Session
CS163/164 Final Exam Study Session Review What is printed? public static void main (String [] args){ String s = "Winter Break"; System.out.println(s.indexOf('c')); System.out.println(s.indexOf('e')); System.out.println(s.charAt(2));
More informationSTUDENT LESSON A12 Iterations
STUDENT LESSON A12 Iterations Java Curriculum for AP Computer Science, Student Lesson A12 1 STUDENT LESSON A12 Iterations INTRODUCTION: Solving problems on a computer very often requires a repetition of
More informationegrapher Language Reference Manual
egrapher Language Reference Manual Long Long: ll3078@columbia.edu Xinli Jia: xj2191@columbia.edu Jiefu Ying: jy2799@columbia.edu Linnan Wang: lw2645@columbia.edu Darren Chen: dsc2155@columbia.edu 1. Introduction
More information2/6/2018. ECE 220: Computer Systems & Programming. Function Signature Needed to Call Function. Signature Include Name and Types for Inputs and Outputs
University of Illinois at Urbana-Champaign Dept. of Electrical and Computer Engineering ECE 220: Computer Systems & Programming C Functions and Examples Signature Include Name and Types for Inputs and
More informationCSE 1223: Introduction to Computer Programming in Java Chapter 6 ArrayLists
CSE 1223: Introduction to Computer Programming in Java Chapter 6 ArrayLists 1 A programming problem Consider the following task: Double values representing grades are read until the user enters a negative
More information4. Java language basics: Function. Minhaeng Lee
4. Java language basics: Function Minhaeng Lee Review : loop Program print from 20 to 10 (reverse order) While/for Program print from 1, 3, 5, 7.. 21 (two interval) Make a condition that make true only
More informationCMSC131. Arrays: The Concept
CMSC131 Data Structures: The Array Arrays: The Concept There are a wide variety of data structures that we can use or create to attempt to hold data in useful, organized, efficient ways. The MaritanPolynomial
More informationQuiz Start Time: 09:34 PM Time Left 82 sec(s)
Quiz Start Time: 09:34 PM Time Left 82 sec(s) Question # 1 of 10 ( Start time: 09:34:54 PM ) Total Marks: 1 While developing a program; should we think about the user interface? //handouts main reusability
More informationIntro to Programming & C Why Program? 1.2 Computer Systems: Hardware and Software. Why Learn to Program?
Intro to Programming & C++ Unit 1 Sections 1.1-4 and 2.1-10, 2.12-13, 2.15-17 CS 1428 Spring 2019 Jill Seaman 1.1 Why Program? Computer programmable machine designed to follow instructions Program a set
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 informationCSE 1223: Exam II Autumn 2016
CSE 1223: Exam II Autumn 2016 Name: Instructions: Do not open the exam before you are told to begin. This exam is closed book, closed notes. You may not use any calculators or any other kind of computing
More informationEntry Point of Execution: the main Method. Elementary Programming. Learning Outcomes. Development Process
Entry Point of Execution: the main Method Elementary Programming EECS1021: Object Oriented Programming: from Sensors to Actuators Winter 2019 CHEN-WEI WANG For now, all your programming exercises will
More informationArrays. Loops + arrays: challenge problem. Arrays (II) An array is a set of variables of the same type accessed by their index.
Arrays Arrays (Savitch, Chapter 7) TOPICS Array Basics Array Loops Array Programming An array is a set of variables of the same type accessed by their index int[] day = new int[4]; 31 28 31 30 day[0] day[2]
More informationDefinition MATH Benjamin V.C. Collins, James A. Swenson MATH 2730
MATH 2730 Benjamin V.C. Collins James A. Swenson s and undefined terms The importance of definition s matter! may be more important in Discrete Math than in any math course that you have had previously.
More information