COSC 236 Section 101 Computer Science 1 -- Prof. Michael A. Soderstrand

Size: px
Start display at page:

Download "COSC 236 Section 101 Computer Science 1 -- Prof. Michael A. Soderstrand"

Transcription

1 COSC 236 Section 101 Computer Science 1 -- Prof. Michael A. Soderstrand

2 COSC 236 Web Site You will always find the course material at: or or From this site you can click on the COSC-236 tab to download the PowerPoint lectures, the Quiz solutions and the Laboratory assignments. 2

3 3

4 Review of Quiz 20 Use Quiz 19 as your model Only the second part of Quiz 19 needs to be modified You will print the array in the order it was entered using Arrays.toString You will the use Arrays.sort to sort the array into ascending order and print it using Arrays.toString Finally you will use your method to reverse the array and print the array in descending order using Arrays.toString 4

5 Review of Quiz 20 The Program form Quiz 19: import java.util.*; public class Quiz19 { public static void main(string[] args) { Scanner console = new Scanner(System.in); System.out.print("How many test scores do you wish to enter? "); int number = console.nextint(); double[] scores = new double[number]; // array to store scores double sum = 0; for (int i = 0; i < number; i++) { // read/store each score System.out.print("Please enter test " + (i + 1) + "'s score: "); scores[i] = console.nextdouble(); sum += scores[i]; double mean = sum / number; System.out.printf("Original Arrays.sort(scores); array = %s\n", Arrays.toString(scores)); Arrays.sort(scores); double high = scores[number-1]; System.out.printf(" double low = scores[0]; Sorted array = %s\n", Arrays.toString(scores)); System.out.printf("Reversed double median = 0; array = %s\n", Arrays.toString(reverse(scores))); if(number%2 == 0) { median = (scores[number/2] + scores[number/2-1])/2; //Add else your { method to reverse the elements of an array public median static = scores[number/2]; double[] reverse(double[] array) { for // report (int i results = 0; i < array.length/2; i++) { System.out.printf("Test double temp = array[i]; Statistics:\n"); System.out.printf(" array[i] = array[array.length High Score: - i %6.2f\n", -1]; high); System.out.printf(" array[array.length - Mean i -1] Score: = temp; %6.2f\n", mean); return System.out.printf(" array; Median Score: %6.2f\n", median); System.out.printf(" Low Score: %6.2f\n", low); Replace this 5

6 Review of Quiz 20 Replaced code: System.out.printf("Original array = %s\n", Arrays.toString(scores)); Arrays.sort(scores); System.out.printf(" Sorted array = %s\n", Arrays.toString(scores)); System.out.printf("Reversed array = %s\n", Arrays.toString(reverse(scores))); public static double[] reverse(double[] array) { Print original array Sort the array for (int i = 0; i < array.length/2; i++) { double temp = array[i]; array[i] = array[array.length - i -1]; array[array.length - i -1] = temp; return array; Print sorted array Print the reversed array The print statement contains the call to your method reverse that reverses the array 6

7 Review of Quiz 20 Replaced code: System.out.printf("Original array = %s\n", Arrays.toString(scores)); Arrays.sort(scores); System.out.printf(" Sorted array = %s\n", Arrays.toString(scores)); System.out.printf("Reversed array = %s\n", Arrays.toString(reverse(scores))); public static double[] reverse(double[] array) { for (int i = 0; i < array.length/2; i++) { double temp = array[i]; array[i] = array[array.length - i -1]; array[array.length - i -1] = temp; return array; Accepts a double precision array as a parameter Explicitly returns the reversed array to the main program NOTE: The array passed by reference as a parameter has already been reversed. The explicit return allows us to use the method in a print statement. 7

8 Review of Quiz 20 OUTPUT: Printout verifies that the sort and reverse do work properly 8

9 7.5 Multidimensional Arrays (Lecture 21) Rectangular Two-Dimensional Arrays (pp ) Jagged Arrays (pp ) 7.6 Case Study: Benford s Law (Lecture 21) Introduction (pp ) Tallying Values (pp ) Completing the Program (pp ) 9

10 7.5 Multidimensional Arrays (Lecture 21) Rectangular Two-Dimensional Arrays (pp ) The arrays that we have used so far are onedimensional They can be considered a single row Or they can be considered a single column Often we need two dimensional arrays Contains both rows and columns double[][]: two dimensional array of rows and columns 10

11 7.5 Multidimensional Arrays (Lecture 21) Rectangular Two-Dimensional Arrays (pp ) Java allows for multidimensional arrays: double[][][]: Three dimensions double[][][][]: Four dimensions etc. We will only use one and two dimensional arrays in COSC-236 These are the most useful in practice The concept is easily extended once you know one and two dimensional arrays 11

12 7.5 Multidimensional Arrays (Lecture 21) Rectangular Two-Dimensional Arrays (pp ) The most common multidimensional array is a twodimensional array of a fixed number of rows and columns: double[][] temps = new double[3][5] The above could be used to store five temperature readings for three days 12

13 7.5 Multidimensional Arrays (Lecture 21) Rectangular Two-Dimensional Arrays (pp ) We can set the values of any element in the array: temps[0][3] = 98.3; temps[2][0] = 99.4 The above results in the following 13

14 7.5 Multidimensional Arrays (Lecture 21) Rectangular Two-Dimensional Arrays (pp ) We can pass an array as a parameter for a method: public static void print(double[][] grid) { for (int i = 0; i < grid.length; i++) { for (int j = 0; j < grid[i].length; j++) { System.out.print(grid[i][j] + " "); System.out.println(); Prints out row i, column j Start new line after each row Use [][] for 2-D array grid.length refers to number of rows grid[i].length refers to the number of columns in row i 14

15 7.5 Multidimensional Arrays (Lecture 21) Rectangular Two-Dimensional Arrays (pp ) We can print multi-dimensional arrays as strings: import java.util.*; public class Lecture21S15 { public static void main(string[] args) { Scanner console = new Scanner(System.in); double[][] temps = new double[3][4]; for (int i = 0; i < 3; i++) { for(int j = 0; j < 4; j++) { System.out.print("Please enter row " + (i+1) + ", col " + (j+1) + ": "); temps[i][j] = console.nextdouble(); System.out.println(Arrays.deepToString(temps)); NOTE: Arrays.toString() does not work for multi-dimensional arrays 15

16 Rectangular 2-D Arrays (pp ) Rectangular Two-Dimensional Arrays (pp ) We can print multi-dimensional arrays as strings: 7.5 Multidimensional Arrays (Lecture 21) import java.util.*; public class Lecture21S15 { public static void main(string[] args) { Scanner console = new Scanner(System.in); double[][] temps = new double[3][4]; for (int i = 0; i < 3; i++) { for(int j = 0; j < 4; j++) { System.out.print("Please enter row " + (i+1) + ", col " + (j+1) + ": "); temps[i][j] = console.nextdouble(); System.out.println(Arrays.deepToString(temps)); 16

17 import java.util.*; public class Lecture21S16 { public static void main(string[] args) { Scanner console = new Scanner(System.in); System.out.print("How many rows? "); int row = console.nextint(); System.out.print("How many columns? "); int col = console.nextint(); double[][] temps = new double[row][col]; for (int i = 0; i < row; i++) { for(int j = 0; j < col; j++) { System.out.print("Please enter row " + (i+1) + ", col " + (j+1) + ": "); temps[i][j] = console.nextdouble(); System.out.println(Arrays.deepToString(temps)); Rectangular 2-D Arrays (pp ) This program allows us to specify the number of rows and columns 17

18 import java.util.*; Rectangular 2-D Arrays (pp ) public class Lecture21S16 { public static void main(string[] args) { Scanner console = new Scanner(System.in); System.out.print("How many rows? "); int row = console.nextint(); System.out.print("How many columns? "); int col = console.nextint(); double[][] temps = new double[row][col]; for (int i = 0; i < row; i++) { for(int j = 0; j < col; j++) { System.out.print("Please enter row " + (i+1) + ", col " + (j+1) + ": "); temps[i][j] = console.nextdouble(); System.out.println(Arrays.deepToString(temps)); 18

19 7.5 Multidimensional Arrays (Lecture 21) Rectangular Two-Dimensional Arrays (pp ) Jagged Arrays (pp ) 7.6 Case Study: Benford s Law (Lecture 21) Introduction (pp ) Tallying Values (pp ) Completing the Program (pp ) 19

20 7.5 Multidimensional Arrays (Lecture 21) Rectangular Two-Dimensional Arrays (pp ) Jagged Arrays (pp ) 20

21 7.5 Multidimensional Arrays (Lecture 21) Jagged Arrays (pp ) Jagged Arrays (pp ) 21

22 public class PascalsTriangle { public static void main(string[] args) { int[][] triangle = new int[11][]; fillin(triangle); Jagged Arrays print(triangle); public static void fillin(int[][] triangle) { for (int i = 0; i < triangle.length; i++) { triangle[i] = new int[i + 1]; triangle[i][0] = 1; triangle[i][i] = 1; for (int j = 1; j < i; j++) { triangle[i][j] = triangle[i-1][j-1] + triangle[i-1][j]; public static void print(int[][] triangle) { for (int i = 0; i < triangle.length; i++) { for (int j = 0; j < triangle[i].length; j++) { System.out.print(triangle[i][j] + " "); System.out.println(); (pp ) 22

23 public class PascalsTriangle { public static void main(string[] args) { int[][] triangle = new int[11][]; fillin(triangle); Jagged Arrays print(triangle); public static void fillin(int[][] triangle) { for (int i = 0; i < triangle.length; i++) { triangle[i] = new int[i + 1]; triangle[i][0] = 1; triangle[i][i] = 1; for (int j = 1; j < i; j++) { triangle[i][j] = triangle[i-1][j-1] + triangle[i-1][j]; public static void print(int[][] triangle) { for (int i = 0; i < triangle.length; i++) { for (int j = 0; j < triangle[i].length; j++) { System.out.print(triangle[i][j] + " "); System.out.println(); (pp ) 23

24 7.5 Multidimensional Arrays (Lecture 21) Rectangular Two-Dimensional Arrays (pp ) Jagged Arrays (pp ) 7.6 Case Study: Benford s Law (Lecture 21) Introduction (pp ) Tallying Values (pp ) Completing the Program (pp ) 24

25 7.6 Case Study: Benford s Law (Lecture 21) Introduction (pp ) Tallying Values (pp ) Completing the Program (pp ) 25

26 7.6 Case Study: Benford s Law (Lecture 21) Introduction (pp ) When real-world data is linear: We expect a uniform distribution of data Looking at the most significant digit of data we would expect each number 1 through 9 to occur 11% of the time (or 0 through 9 10% of the time) But real-world data is more often exponential than it is linear! 26

27 7.6 Case Study: Benford s Law (Lecture 21) Introduction (pp ) When real-world data is exponential: We expect data to conform to Benford s Law Benford s Law predicts far more low numbers than high number for the most significant digit Benford provided a table that quantifies this result 27

28 7.6 Case Study: Benford s Law (Lecture 21) Introduction (pp ) When real-world data is exponential: Introduction We expect data to conform to Benford s (pp. Law ) Benford s Law predicts far more low numbers than high number for the most significant digit Benford provided a table that quantifies this result 28

29 7.6 Case Study: Benford s Law (Lecture 21) Introduction (pp ) Tallying Values (pp ) Completing the Program (pp ) 29

30 7.6 Case Study: Benford s Law (Lecture 21) Introduction (pp ) Tallying Values (pp ) 30

31 A multi-counter problem (pp ) Problem: Write a method mostfrequentdigit that returns the digit value that occurs most frequently in a number. Example: The number contains: one 0, two 2s, four 6es, one 7, and one 9. mostfrequentdigit( ) returns 6. If there is a tie, return the digit with the lower value. mostfrequentdigit( ) returns 3. 31

32 A multi-counter problem (pp ) We could declare 10 counter variables... int counter0, counter1, counter2, counter3, counter4, counter5, counter6, counter7, counter8, counter9; But a better solution is to use an array of size 10. The element at index i will store the counter for digit value i. Example for : index value How do we build such an array? And how does it help? 32

33 Creating an array of tallies (pp ) // assume n = int[] counts = new int[10]; while (n > 0) { // pluck off a digit and add to proper counter int digit = n % 10; counts[digit]++; n = n / 10; index value

34 Tally solution (pp ) // Returns the digit value that occurs most frequently in n. // Breaks ties by choosing the smaller value. public static int mostfrequentdigit(int n) { int[] counts = new int[10]; while (n > 0) { int digit = n % 10; // pluck off a digit and tally it counts[digit]++; n = n / 10; // find the most frequently occurring digit int bestindex = 0; for (int i = 1; i < counts.length; i++) { if (counts[i] > counts[bestindex]) { bestindex = i; return bestindex; Set up the tally array While number is non zero Tally Ready the next digit The array counts now has a tally of how many times each digit occurs 34

35 Tally solution (pp ) // Returns the digit value that occurs most frequently in n. // Breaks ties by choosing the smaller value. public static int mostfrequentdigit(int n) { int[] counts = new int[10]; while (n > 0) { int digit = n % 10; // pluck off a digit and tally it counts[digit]++; n = n / 10; // find the most frequently occurring digit int bestindex = 0; for (int i = 1; i < counts.length; i++) { if (counts[i] > counts[bestindex]) { bestindex = i; return bestindex; We can now check through the array count to look for the most frequently occurring digit Zero the index finder Check through the array for index with maximum count Return that maximum index 35

36 Array histogram question (pp ) Given a file of integer exam scores, such as: Write a program that will print a histogram of stars indicating the number of students who earned each unique exam score. 85: ***** 86: ************ 87: *** 88: * 91: **** NOTE: This histogram does not refer to the previous data 36

37 Array histogram answer (pp ) 37

38 Array // Reads a file histogram of test scores and shows answer a histogram of score (pp. distribution ) import java.io.*; import java.util.*; public class Histogram { public static void main(string[] args) throws FileNotFoundException { Scanner input = new Scanner(new File("midterm.txt")); int[] counts = new int[101]; // counters of test scores while (input.hasnextint()) { int score = input.nextint(); counts[score]++; // read file into counts array // if score is 87, then counts[87]++ for (int i = 0; i < counts.length; i++) { if (counts[i] > 0) { System.out.print(i + ": "); for (int j = 0; j < counts[i]; j++) { System.out.print("*"); System.out.println(); // print star histogram 38

39 Section attendance question Read a file of section attendance (see next slide): yynyyynayayynyyyayanyyyaynayyayyanayyyanyayna ayyanyyyyayanaayyanayyyananayayaynyayayynynya yyayaynyyayyanynnyyyayyanayaynannnyyayyayayny And produce the following output: Section 1 Student points: [20, 17, 19, 16, 13] Student grades: [100.0, 85.0, 95.0, 80.0, 65.0] Section 2 Student points: [17, 20, 16, 16, 10] Student grades: [85.0, 100.0, 80.0, 80.0, 50.0] Section 3 Student points: [17, 18, 17, 20, 16] Student grades: [85.0, 90.0, 85.0, 100.0, 80.0] Students earn 3 points for each section attended up to

40 Section input file student week section 1 section 2 section 3 yynyyynayayynyyyayanyyyaynayyayyanayyyanyayna ayyanyyyyayanaayyanayyyananayayaynyayayynynya yyayaynyyayyanynnyyyayyanayaynannnyyayyayayny Each line represents a section. A line consists of 9 weeks' worth of data. Each week has 5 characters because there are 5 students. Within each week, each character represents one student. a means the student was absent n means they attended but didn't do the problems y means they attended and did the problems (+0 points) (+2 points) (+3 points) 40

41 Section attendance answer import java.io.*; import java.util.*; public class Sections { public static void main(string[] args) throws FileNotFoundException { Scanner input = new Scanner(new File("sections.txt")); int section = 1; while (input.hasnextline()) { String line = input.nextline(); // process one section int[] points = new int[5]; for (int i = 0; i < line.length(); i++) { int student = i % 5; int earned = 0; if (line.charat(i) == 'y') { // c == 'y' or 'n' or 'a' earned = 3; else if (line.charat(i) == 'n') { earned = 2; points[student] = Math.min(20, points[student] + earned); double[] grades = new double[5]; for (int i = 0; i < points.length; i++) { grades[i] = * points[i] / 20.0; System.out.println("Section " + section); System.out.println("Student points: Arrays.toString(points)); System.out.println("Student grades: " + Arrays.toString(grades)); System.out.println(); section++; 41

42 Data transformations In many problems we transform data between forms. Example: digits count of each digit most frequent digit Often each transformation is computed/stored as an array. For structure, a transformation is often put in its own method. Sometimes we map between data and array indexes. by position (store the i th value we read at index i ) tally (if input value is i, store it at array index i ) explicit mapping (count 'J' at index 0, count 'X' at index 1) Exercise: Modify our Sections program to use static methods that use arrays as parameters and returns. 42

43 Array param/return answer // This program reads a file representing which students attended // which discussion sections and produces output of the students' // section attendance and scores. import java.io.*; import java.util.*; public class Sections2 { public static void main(string[] args) throws FileNotFoundException { Scanner input = new Scanner(new File("sections.txt")); int section = 1; while (input.hasnextline()) { // process one section String line = input.nextline(); int[] points = countpoints(line); double[] grades = computegrades(points); results(section, points, grades); section++; // Produces all output about a particular section. public static void results(int section, int[] points, double[] grades) { System.out.println("Section " + section); System.out.println("Student scores: " + Arrays.toString(points)); System.out.println("Student grades: " + Arrays.toString(grades)); System.out.println();... 43

44 Array param/return answer... // Computes the points earned for each student for a particular section. public static int[] countpoints(string line) { int[] points = new int[5]; for (int i = 0; i < line.length(); i++) { int student = i % 5; int earned = 0; if (line.charat(i) == 'y') { // c == 'y' or c == 'n' earned = 3; else if (line.charat(i) == 'n') { earned = 2; points[student] = Math.min(20, points[student] + earned); return points; // Computes the percentage for each student for a particular section. public static double[] computegrades(int[] points) { double[] grades = new double[5]; for (int i = 0; i < points.length; i++) { grades[i] = * points[i] / 20.0; return grades; 44

45 Assignments for this week 1. Laboratory for Chapter 7 due next Monday 11/17 IMPORTANT: When you me your laboratory Word Document, be sure it is all in one file 2. Read pp (Chapter 13) for Monday 11/12 3. Be sure to complete Quiz 21 before leaving class tonight This is another program to write You must demonstrate the program to me before you leave lab 45

Building Java Programs

Building Java Programs Building Java Programs Chapter 7 Lecture 7-3: Arrays for Tallying; Text Processing reading: 7.6, 4.3 A multi-counter problem Problem: Write a method mostfrequentdigit that returns the digit value that

More information

Topic 23 arrays - part 3 (tallying, text processing)

Topic 23 arrays - part 3 (tallying, text processing) Topic 23 arrays - part 3 (tallying, text processing) "42 million of anything is a lot." -Doug Burger (commenting on the number of transistors in the Pentium IV processor) Copyright Pearson Education, 2010

More information

Building Java Programs Chapter 7

Building Java Programs Chapter 7 Building Java Programs Chapter 7 Arrays Copyright (c) Pearson 2013. All rights reserved. Can we solve this problem? Consider the following program (input underlined): How many days' temperatures? 7 Day

More information

Array basics. How would you solve this? Arrays. What makes the problem hard? Array auto-initialization. Array declaration. Readings: 7.

Array basics. How would you solve this? Arrays. What makes the problem hard? Array auto-initialization. Array declaration. Readings: 7. How would you solve this? Array basics Readings:. Consider the following program: How many days' temperatures? Day 's high temp: Day 's high temp: Day 's high temp: Day 's high temp: Day 's high temp:

More information

Array basics. Readings: 7.1

Array basics. Readings: 7.1 Array basics Readings: 7.1 1 How would you solve this? Consider the following program: How many days' temperatures? 7 Day 1's high temp: 45 Day 2's high temp: 44 Day 3's high temp: 39 Day 4's high temp:

More information

Building Java Programs

Building Java Programs Building Java Programs Chapter 7 Lecture 7-3: Arrays as Parameters; File Output reading: 7.1, 4.3, 3.3 self-checks: Ch. 7 #19-23 exercises: Ch. 7 #5 Section attendance question Write a program that reads

More information

COSC 236 Section 101 Computer Science 1 -- Prof. Michael A. Soderstrand

COSC 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 You will always find the course material at: http://www.class-notes.us or http://www.class-notes.info or http://www.lecture-notes.tripod.com

More information

Building Java Programs

Building Java Programs Building Java Programs Chapter 7 Lecture 7-3: Arrays as Parameters; File Output reading: 7.1, 4.3, 3.3 self-checks: Ch. 7 #19-23 exercises: Ch. 7 #5 Section attendance question Write a program that reads

More information

Building Java Programs

Building Java Programs Building Java Programs Chapter 7: Arrays Lecture 7-3: More text processing, file output 1 Remember: charat method Strings are internally represented as char arrays String traversals are a common form of

More information

COSC 236 Section 101 Computer Science 1 -- Prof. Michael A. Soderstrand

COSC 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 You will always find the course material at: http://www.class-notes.us or http://www.class-notes.info or http://www.lecture-notes.tripod.com

More information

Building Java Programs

Building Java Programs Building Java Programs Chapter 6: File Processing Lecture 6-2: Advanced file input reading: 6.3-6.5 self-check: #7-11 exercises: #1-4, 8-11 Copyright 2009 by Pearson Education Hours question Given a file

More information

COSC 236 Section 101 Computer Science 1 -- Prof. Michael A. Soderstrand

COSC 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 You will always find the course material at: http://www.class-notes.us or http://www.class-notes.info or http://www.lecture-notes.tripod.com

More information

COSC 236 Section 101 Computer Science 1 -- Prof. Michael A. Soderstrand

COSC 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 You will always find the course material at: http://www.class-notes.us or http://www.class-notes.info or http://www.lecture-notes.tripod.com

More information

Admin. CS 112 Introduction to Programming. Recap: Arrays. Arrays class. Array Return (call) Array Return (declare) q Exam 1 Max: 50 Avg/median: 32

Admin. CS 112 Introduction to Programming. Recap: Arrays. Arrays class. Array Return (call) Array Return (declare) q Exam 1 Max: 50 Avg/median: 32 Admin 100# 95# 90# 85# 80# CS 112 Introduction to Programming q Exam 1 Max: 50 Avg/median: 32 75# 70# 65# 60# 55# 50# 45# 40# 35# 30# 25# Reference Semantics; 2D Arrays; Array as State Yang (Richard) Yang

More information

CS 112 Introduction to Programming

CS 112 Introduction to Programming CS 112 Introduction to Programming Reference Semantics; 2D Arrays; Array as State Yang (Richard) Yang Computer Science Department Yale University 308A Watson, Phone: 432-6400 Email: yry@cs.yale.edu Admin

More information

CS 112 Introduction to Programming

CS 112 Introduction to Programming CS 112 Introduction to Programming Reference Semantics; 2D Arrays; Array as State Yang (Richard) Yang Computer Science Department Yale University 308A Watson, Phone: 432-6400 Email: yry@cs.yale.edu Admin

More information

COSC 236 Section 101 Computer Science 1 -- Prof. Michael A. Soderstrand

COSC 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 You will always find the course material at: http://www.class-notes.us or http://www.class-notes.info or http://www.lecture-notes.tripod.com

More information

COSC 236 Section 101 Computer Science 1 -- Prof. Michael A. Soderstrand

COSC 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 You will always find the course material at: http://www.class-notes.us or http://www.class-notes.info or http://www.lecture-notes.tripod.com

More information

COSC 236 Section 101 Computer Science 1 -- Prof. Michael A. Soderstrand

COSC 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 You will always find the course material at: http://www.class-notes.us or http://www.class-notes.info or http://www.lecture-notes.tripod.com

More information

Building Java Programs

Building Java Programs Building Java Programs Chapter 7 Lecture 7-3: File Output; Reference Semantics reading: 6.4-6.5, 7.1, 4.3, 3.3 self-checks: Ch. 7 #19-23 exercises: Ch. 7 #5 Two separate topics File output A lot like printing

More information

Object Oriented Programming. Java-Lecture 6 - Arrays

Object Oriented Programming. Java-Lecture 6 - Arrays Object Oriented Programming Java-Lecture 6 - Arrays Arrays Arrays are data structures consisting of related data items of the same type In Java arrays are objects -> they are considered reference types

More information

COSC 236 Section 101 Computer Science 1 -- Prof. Michael A. Soderstrand

COSC 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 You will always find the course material at: http://www.class-notes.us From this site you can click on the COSC-236

More information

COSC 236 Section 101 Computer Science 1 -- Prof. Michael A. Soderstrand

COSC 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 You will always find the course material at: http://www.class-notes.us From this site you can click on the COSC-236

More information

Arrays. Weather Problem Array Declaration Accessing Elements Arrays and for Loops Array length field Quick Array Initialization Array Traversals

Arrays. Weather Problem Array Declaration Accessing Elements Arrays and for Loops Array length field Quick Array Initialization Array Traversals Arrays Weather Problem Array Declaration Accessing Elements Arrays and for Loops Array length field Quick Array Initialization Array Traversals Can we solve this problem? Consider the following program

More information

COSC 236 Section 101 Computer Science 1 -- Prof. Michael A. Soderstrand

COSC 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 You will always find the course material at: http://www.class-notes.us or http://www.class-notes.info or http://www.lecture-notes.tripod.com

More information

COSC 236 Section 101 Computer Science 1 -- Prof. Michael A. Soderstrand

COSC 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 You will always find the course material at: http://www.class-notes.us or http://www.class-notes.info or http://www.lecture-notes.tripod.com

More information

Last Class. More on loops break continue A bit on arrays

Last 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 information

CS 112 Introduction to Programming

CS 112 Introduction to Programming CS 112 Introduction to Programming Program Analysis Yang (Richard) Yang Computer Science Department Yale University 308A Watson, Phone: 432-6400 Email: yry@cs.yale.edu Admin q PS5 Walkthrough Thursday

More information

Arrays. Eng. Mohammed Abdualal

Arrays. 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 information

Exercise 4: Loops, Arrays and Files

Exercise 4: Loops, Arrays and Files Exercise 4: Loops, Arrays and Files worth 24% of the final mark November 4, 2004 Instructions Submit your programs in a floppy disk. Deliver the disk to Michele Zito at the 12noon lecture on Tuesday November

More information

Recitation: Loop Jul 7, 2008

Recitation: Loop Jul 7, 2008 Nested Loop Recitation: Loop Jul 7, 2008 1. What is the output of the following program? Use pen and paper only. The output is: ****** ***** **** *** ** * 2. Test this program in your computer 3. Use "for

More information

while (/* array size less than 1*/){ System.out.print("Number of students is invalid. Enter" + "number of students: "); /* read array size again */

while (/* array size less than 1*/){ System.out.print(Number of students is invalid. Enter + number of students: ); /* read array size again */ import java.util.scanner; public class CourseManager1 { public static void main(string[] args) { Scanner input = new Scanner(System.in); System.out.print("Enter number of students: "); /* read the number

More information

Building Java Programs

Building Java Programs Building Java Programs Chapter 7 Arrays reading: 7.1 2 Can we solve this problem? Consider the following program (input underlined): How many days' temperatures? 7 Day 1's high temp: 45 Day 2's high temp:

More information

Chapter 8 Multi-Dimensional Arrays

Chapter 8 Multi-Dimensional Arrays Chapter 8 Multi-Dimensional Arrays 1 1-Dimentional and 2-Dimentional Arrays In the previous chapter we used 1-dimensional arrays to model linear collections of elements. myarray: 6 4 1 9 7 3 2 8 Now think

More information

COSC 236 Section 101 Computer Science 1 -- Prof. Michael A. Soderstrand

COSC 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 You will always find the course material at: http://www.class-notes.us From this site you can click on the COSC-236

More information

CSc 110, Autumn Lecture 26: Assertions. Adapted from slides by Marty Stepp and Stuart Reges

CSc 110, Autumn Lecture 26: Assertions. Adapted from slides by Marty Stepp and Stuart Reges CSc 110, Autumn 2017 Lecture 26: Assertions Adapted from slides by Marty Stepp and Stuart Reges Section attendance question Read a file of section attendance (see next slide): yynyyynayayynyyyayanyyyaynayyayyanayyyanyayna

More information

Chapter 7 Multidimensional Arrays. Liang, Introduction to Java Programming, Tenth Edition, (c) 2013 Pearson Education, Inc. All rights reserved.

Chapter 7 Multidimensional Arrays. Liang, Introduction to Java Programming, Tenth Edition, (c) 2013 Pearson Education, Inc. All rights reserved. Chapter 7 Multidimensional Arrays rights reserved. 1 Motivations Thus far, you have used one-dimensional arrays to model linear collections of elements. You can use a two-dimensional array to represent

More information

Liang, Introduction to Java Programming, Eighth Edition, (c) 2011 Pearson Education, Inc. All rights reserved

Liang, Introduction to Java Programming, Eighth Edition, (c) 2011 Pearson Education, Inc. All rights reserved 1 Thus far, you have used one-dimensional arrays to model linear collections of elements. You can use a two-dimensional array to represent a matrix or a table. For example, the following table that describes

More information

1. An operation in which an overall value is computed incrementally, often using a loop.

1. An operation in which an overall value is computed incrementally, often using a loop. Practice Exam 2 Part I: Vocabulary (10 points) Write the terms defined by the statements below. 1. An operation in which an overall value is computed incrementally, often using a loop. 2. The < (less than)

More information

Chapter 6 Arrays, Part D 2d Arrays and the Arrays Class

Chapter 6 Arrays, Part D 2d Arrays and the Arrays Class Chapter 6 Arrays, Part D 2d Arrays and the Arrays Class Section 6.10 Two Dimensional Arrays 1. The arrays we have studied so far are one dimensional arrays, which we usually just call arrays. Twodimensional

More information

Object Oriented Programming. Java-Lecture 1

Object Oriented Programming. Java-Lecture 1 Object Oriented Programming Java-Lecture 1 Standard output System.out is known as the standard output object Methods to display text onto the standard output System.out.print prints text onto the screen

More information

COSC 236 Section 101 Computer Science 1 -- Prof. Michael A. Soderstrand

COSC 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 You will always find the course material at: http://www.class-notes.us From this site you can click on the COSC-236

More information

Bjarne Stroustrup. creator of C++

Bjarne Stroustrup. creator of C++ We Continue GEEN163 I have always wished for my computer to be as easy to use as my telephone; my wish has come true because I can no longer figure out how to use my telephone. Bjarne Stroustrup creator

More information

Reading Input from Text File

Reading Input from Text File Islamic University of Gaza Faculty of Engineering Computer Engineering Department Computer Programming Lab (ECOM 2114) Lab 5 Reading Input from Text File Eng. Mohammed Alokshiya November 2, 2014 The simplest

More information

Last 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 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 information

Last Class. While loops Infinite loops Loop counters Iterations

Last 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 information

Building Java Programs

Building Java Programs Building Java Programs Chapter 4 Lecture 4-1: if and if/else Statements reading: 4.2 self-check: #4-5, 7, 10, 11 exercises: #7 videos: Ch. 4 #2-4 The if/else statement Executes one block if a test is true,

More information

Topic 21 arrays - part 1

Topic 21 arrays - part 1 Topic 21 arrays - part 1 "Should array indices start at 0 or 1? My compromise of 0.5 was rejected without, I thought, proper consideration. " - Stan Kelly-Bootle Copyright Pearson Education, 2010 Based

More information

Building Java Programs

Building Java Programs Building Java Programs Chapter 4: Conditional Execution 1 loop techniques cumulative sum fencepost loops conditional execution Chapter outline the if statement and the if/else statement relational expressions

More information

COSC 236 Section 101 Computer Science 1 -- Prof. Michael A. Soderstrand

COSC 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 You will always find the course material at: http://www.class-notes.us or http://www.class-notes.info or http://www.lecture-notes.tripod.com

More information

Loops. Eng. Mohammed Abdualal. Islamic University of Gaza. Faculty of Engineering. Computer Engineering Department

Loops. Eng. Mohammed Abdualal. Islamic University of Gaza. Faculty of Engineering. Computer Engineering Department 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 6 Loops

More information

CS111: PROGRAMMING LANGUAGE II

CS111: 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 information

Building Java Programs

Building Java Programs Building Java Programs Chapter 6 Lecture 6-3: Searching Files reading: 6.3-6.5 2 Recall: Line-based methods Method nextline() Description returns the next entire line of input hasnextline() returns true

More information

Building Java Programs

Building Java Programs Building Java Programs Chapter 3: Parameters, Return, and Interactive Programs with Scanner 1 Lecture outline console input with Scanner objects input tokens Scanner as a parameter to a method cumulative

More information

CSE 143 Lecture 10. Recursion

CSE 143 Lecture 10. Recursion CSE 143 Lecture 10 Recursion slides created by Marty Stepp and Alyssa Harding http://www.cs.washington.edu/143/ Recursion Iteration: a programming technique in which you describe actions to be repeated

More information

Arrays. Chapter 7 Part 3 Multi-Dimensional Arrays

Arrays. Chapter 7 Part 3 Multi-Dimensional Arrays Arrays Chapter 7 Part 3 Multi-Dimensional Arrays Chapter 7: Arrays Slide # 1 Agenda Array Dimensions Multi-dimensional arrays Basics Printing elements Chapter 7: Arrays Slide # 2 First Some Video Tutorials

More information

COSC 236 Section 101 Computer Science 1 -- Prof. Michael A. Soderstrand

COSC 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 information

Building Java Programs

Building Java Programs Building Java Programs Chapter 4 Lecture 4-1: if and if/else Statements reading: 4.2 self-check: #4-5, 7, 10, 11 exercises: #7 videos: Ch. 4 #2-4 Loops with if/else if/else statements can be used with

More information

arrays - part 1 My methods are really methods of working and thinking; this is why they have crept in everywhere anonymously. Emmy Noether, Ph.D.

arrays - part 1 My methods are really methods of working and thinking; this is why they have crept in everywhere anonymously. Emmy Noether, Ph.D. Topic 21 https://commons.wikimedia.org/w/index.php?curid=66702 arrays - part 1 My methods are really methods of working and thinking; this is why they have crept in everywhere anonymously. Emmy Noether,

More information

CSE 142, Spring Chapters 6 and 7 Line-Based File Input, Arrays. reading: , 7.1

CSE 142, Spring Chapters 6 and 7 Line-Based File Input, Arrays. reading: , 7.1 CSE 142, Spring 2013 Chapters 6 and 7 Line-Based File Input, Arrays reading: 6.3-6.5, 7.1 Programming feel like that? 2 IMDb movies problem Consider the following Internet Movie Database (IMDb) data: 1

More information

Lecture 13: Two- Dimensional Arrays

Lecture 13: Two- Dimensional Arrays Lecture 13: Two- Dimensional Arrays Building Java Programs: A Back to Basics Approach by Stuart Reges and Marty Stepp Copyright (c) Pearson 2013. All rights reserved. Nested Loops Nested loops nested loop:

More information

Garfield AP CS. User Input, If/Else. Most slides from Building Java Programs. Thanks, Stuart Regesand Marty Stepp!

Garfield AP CS. User Input, If/Else. Most slides from Building Java Programs. Thanks, Stuart Regesand Marty Stepp! Garfield AP CS User Input, If/Else Most slides from Building Java Programs. Thanks, Stuart Regesand Marty Stepp! Warmup Write a method add10 that takes one integer parameter. Your method should return

More information

Building Java Programs

Building Java Programs Building Java Programs Chapter 6: File Processing Lecture 6-1: File input using Scanner reading: 6.1-6.2, 5.3 self-check: Ch. 6 #1-6 exercises: Ch. 6 #5-7 Input/output ("I/O") import java.io.*; Create

More information

Arrays and Lists CSC 121 Fall 2014 Howard Rosenthal

Arrays and Lists CSC 121 Fall 2014 Howard Rosenthal Arrays and Lists CSC 121 Fall 2014 Howard Rosenthal Lesson Goals Understand what an array is Understand how to declare arrays Understand what reference variables are Understand how to pass arrays to methods

More information

Web-CAT submission URL: CAT.woa/wa/assignments/eclipse

Web-CAT submission URL:  CAT.woa/wa/assignments/eclipse King Saud University College of Computer & Information Science CSC111 Lab10 Arrays II All Sections ------------------------------------------------------------------- Instructions Web-CAT submission URL:

More information

Menu Driven Systems. While loops, menus and the switch statement. Mairead Meagher Dr. Siobhán Drohan. Produced by:

Menu Driven Systems. While loops, menus and the switch statement. Mairead Meagher Dr. Siobhán Drohan. Produced by: Menu Driven Systems While loops, menus and the switch statement Produced by: Mairead Meagher Dr. Siobhán Drohan Department of Computing and Mathematics http://www.wit.ie/ Topics list while loops recap

More information

Chapter 8 Multidimensional Arrays

Chapter 8 Multidimensional Arrays Chapter 8 Multidimensional Arrays 8.1 Introduction Thus far, you have used one-dimensional arrays to model linear collections of elements. You can use a two-dimensional array to represent a matrix or a

More information

Building Java Programs

Building Java Programs Building Java Programs Chapter 6 Lecture 6-1: File Input with Scanner reading: 6.1-6.2, 5.3 self-check: Ch. 6 #1-6 exercises: Ch. 6 #5-7 videos: Ch. 6 #1-2 Input/output (I/O) import java.io.*; Create a

More information

Tasks for fmri-setting (Tasks of first and second pilot study at the end)

Tasks for fmri-setting (Tasks of first and second pilot study at the end) Tasks for fmri-setting (Tasks of first and second pilot study at the end) 1. Faculty int result = 1; int x = 4; while (x > 1) { result = result * x; x--; 7. Find max in list of numbers public static void

More information

Example: Computing prime numbers

Example: 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 information

AL GHURAIR UNIVERSITY College of Computing. Objectives: Examples: Text-printing program. CSC 209 JAVA I

AL GHURAIR UNIVERSITY College of Computing. Objectives: Examples: Text-printing program. CSC 209 JAVA I AL GHURAIR UNIVERSITY College of Computing CSC 209 JAVA I week 2- Arithmetic and Decision Making: Equality and Relational Operators Objectives: To use arithmetic operators. The precedence of arithmetic

More information

Top-Down Program Development

Top-Down Program Development Top-Down Program Development Top-down development is a way of thinking when you try to solve a programming problem It involves starting with the entire problem, and breaking it down into more manageable

More information

JAVA PROGRAMMING LAB. ABSTRACT In this Lab you will learn to write programs for executing statements repeatedly using a while, do while and for loop

JAVA PROGRAMMING LAB. ABSTRACT In this Lab you will learn to write programs for executing statements repeatedly using a while, do while and for loop Islamic University of Gaza Faculty of Engineering Computer Engineering Dept. Computer Programming Lab (ECOM 2114) ABSTRACT In this Lab you will learn to write programs for executing statements repeatedly

More information

CS141 Programming Assignment #6

CS141 Programming Assignment #6 CS141 Programming Assignment #6 Due Sunday, Nov 18th. 1) Write a class with methods to do the following output: a) 5 5 5 5 5 4 4 4 4 3 3 3 2 2 1 b) 1 2 3 4 5 4 3 2 1 1 2 3 4 * 4 3 2 1 1 2 3 * * * 3 2 1

More information

CAT.woa/wa/assignments/eclipse

CAT.woa/wa/assignments/eclipse King Saud University College of Computer & Information Science CSC111 Lab10 Arrays II All Sections ------------------------------------------------------------------- Instructions Web-CAT submission URL:

More information

CONTENTS: Array Usage Multi-Dimensional Arrays Reference Types. COMP-202 Unit 6: Arrays

CONTENTS: Array Usage Multi-Dimensional Arrays Reference Types. COMP-202 Unit 6: Arrays CONTENTS: Array Usage Multi-Dimensional Arrays Reference Types COMP-202 Unit 6: Arrays Introduction (1) Suppose you want to write a program that asks the user to enter the numeric final grades of 350 COMP-202

More information

CS/IT 114 Introduction to Java, Part 1 FALL 2016 CLASS 19: NOV. 15TH INSTRUCTOR: JIAYIN WANG

CS/IT 114 Introduction to Java, Part 1 FALL 2016 CLASS 19: NOV. 15TH INSTRUCTOR: JIAYIN WANG CS/IT 114 Introduction to Java, Part 1 FALL 2016 CLASS 19: NOV. 15TH INSTRUCTOR: JIAYIN WANG 1 Notice Assignment Class Exercise 19 is assigned Homework 8 is assigned Both Homework 8 and Exercise 19 are

More information

Introduction. Data in a table or a matrix can be represented using a two-dimensional array. For example:

Introduction. Data in a table or a matrix can be represented using a two-dimensional array. For example: Chapter 7 MULTIDIMENSIONAL ARRAYS Lecture notes for computer programming 1 Faculty of Engineering and Information Technology Prepared by: Iyad Albayouk ١ Introduction Data in a table or a matrix can be

More information

Topic 12 more if/else, cumulative algorithms, printf

Topic 12 more if/else, cumulative algorithms, printf Topic 12 more if/else, cumulative algorithms, printf "We flew down weekly to meet with IBM, but they thought the way to measure software was the amount of code we wrote, when really the better the software,

More information

Arrays and Lists CSC 121 Fall 2016 Howard Rosenthal

Arrays and Lists CSC 121 Fall 2016 Howard Rosenthal Arrays and Lists CSC 121 Fall 2016 Howard Rosenthal Lesson Goals Understand what an array is Understand how to declare arrays Understand what reference variables are Understand how to pass arrays to methods

More information

Faculty of Science COMP-202A - Foundations of Computing (Fall 2013) - All Sections Midterm Examination

Faculty of Science COMP-202A - Foundations of Computing (Fall 2013) - All Sections Midterm Examination First Name: Last Name: McGill ID: Section: Faculty of Science COMP-202A - Foundations of Computing (Fall 2013) - All Sections Midterm Examination November 11th, 2013 Examiners: Jonathan Tremblay [Sections

More information

AP Computer Science. File Input with Scanner. Copyright 2010 by Pearson Education

AP Computer Science. File Input with Scanner. Copyright 2010 by Pearson Education AP Computer Science File Input with Scanner Input/output (I/O) import java.io.*; Create a File object to get info about a file on your drive. (This doesn't actually create a new file on the hard disk.)

More information

Building Java Programs

Building Java Programs Building Java Programs Chapter 5 Lecture 5-4: do/while loops, assertions reading: 5.1, 5.5 1 The do/while loop do/while loop: Performs its test at the end of each repetition. Guarantees that the loop's

More information

Topic 11 Scanner object, conditional execution

Topic 11 Scanner object, conditional execution Topic 11 Scanner object, conditional execution "There are only two kinds of programming languages: those people always [complain] about and those nobody uses." Bjarne Stroustroup, creator of C++ Copyright

More information

NoSuchElementException 5. Name of the Exception that occurs when you try to read past the end of the input data in a file.

NoSuchElementException 5. Name of the Exception that occurs when you try to read past the end of the input data in a file. CSC116 Practice Exam 2 - KEY Part I: Vocabulary (10 points) Write the terms defined by the statements below. Cumulative Algorithm 1. An operation in which an overall value is computed incrementally, often

More information

Tutorial about Arrays

Tutorial about Arrays Q1: Write Java statements that do the following: Reviewed Tutorial about Arrays a. Declare an array alpha of 15 components of the type int int alpha[] = new int[15]; b. Print the value of the tenth component

More information

Instructor: Eng.Omar Al-Nahal

Instructor: Eng.Omar Al-Nahal Faculty of Engineering & Information Technology Software Engineering Department Computer Science [2] Lab 6: Introduction in arrays Declaring and Creating Arrays Multidimensional Arrays Instructor: Eng.Omar

More information

CS141 Programming Assignment #4

CS141 Programming Assignment #4 Due Monday, Oct 31. CS141 Programming Assignment #4 1- Write a program to read in 10 numbers and compute the average, maximum and minimum values (using both while and for loop). Solution 1: * assignment

More information

Chapter 2: Basic Elements of Java

Chapter 2: Basic Elements of Java Chapter 2: Basic Elements of Java TRUE/FALSE 1. The pair of characters // is used for single line comments. ANS: T PTS: 1 REF: 29 2. The == characters are a special symbol in Java. ANS: T PTS: 1 REF: 30

More information

Building Java Programs

Building Java Programs Building Java Programs Chapter 4 Lecture 4-1: Scanner; if/else reading: 3.3 3.4, 4.1, 4.5 2 Interactive Programs with Scanner reading: 3.3-3.4 Interactive programs We have written programs that print console

More information

Building Java Programs

Building Java Programs Building Java Programs Chapter 5 Lecture 5-2: Random Numbers reading: 5.1, 5.6 1 http://xkcd.com/221/ 2 Randomness Lack of predictability: don't know what's coming next Random process: outcomes do not

More information

Building Java Programs

Building Java Programs Building Java Programs Chapter 5 Lecture 5-4: do/while loops, assertions reading: 5.1, 5.5 1 The do/while loop do/while loop: Performs its test at the end of each repetition. Guarantees that the loop's

More information

Arrays and Lists CSC 121 Fall 2015 Howard Rosenthal

Arrays and Lists CSC 121 Fall 2015 Howard Rosenthal Arrays and Lists CSC 121 Fall 2015 Howard Rosenthal Lesson Goals Understand what an array is Understand how to declare arrays Understand what reference variables are Understand how to pass arrays to methods

More information

AL GHURAIR UNIVERSITY College of Computing. Objectives: Examples: if Single-Selection Statement CSC 209 JAVA I. week 3- Control Statements: Part I

AL GHURAIR UNIVERSITY College of Computing. Objectives: Examples: if Single-Selection Statement CSC 209 JAVA I. week 3- Control Statements: Part I AL GHURAIR UNIVERSITY College of Computing CSC 209 JAVA I week 3- Control Statements: Part I Objectives: To use the if and if...else selection statements to choose among alternative actions. To use the

More information

Introduction to Algorithms and Data Structures

Introduction to Algorithms and Data Structures Introduction to Algorithms and Data Structures Lecture 4 Structuring Data: Multidimensional Arrays, Arrays of Objects, and Objects Containing Arrays Grouping Data We don t buy individual eggs; we buy them

More information

Building Java Programs

Building Java Programs Building Java Programs Chapter 6: File Processing 1 Lecture outline line-based file processing using Scanners processing a file line by line mixing line-based and token-based file processing searching

More information

Building Java Programs

Building Java Programs Building Java Programs Chapter 6 Lecture 6-2: Line-Based File Input reading: 6.3-6.5 2 Hours question Given a file hours.txt with the following contents: 123 Ben 12.5 8.1 7.6 3.2 456 Greg 4.0 11.6 6.5

More information

COMP-202B - Introduction to Computing I (Winter 2011) - All Sections Example Questions for In-Class Quiz

COMP-202B - Introduction to Computing I (Winter 2011) - All Sections Example Questions for In-Class Quiz COMP-202B - Introduction to Computing I (Winter 2011) - All Sections Example Questions for In-Class Quiz The in-class quiz is intended to give you a taste of the midterm, give you some early feedback about

More information

CSE 142, Autumn 2011 Midterm Exam: Friday, November 4, 2011

CSE 142, Autumn 2011 Midterm Exam: Friday, November 4, 2011 CSE 142, Autumn 2011 Midterm Exam: Friday, November 4, 2011 Name: Section: Student ID #: TA: You have 50 minutes to complete this exam. You may receive a deduction if you keep working after the instructor

More information

CS Week 5. Jim Williams, PhD

CS Week 5. Jim Williams, PhD CS 200 - Week 5 Jim Williams, PhD The Study Cycle Check Am I using study methods that are effective? Do I understand the material enough to teach it to others? http://students.lsu.edu/academicsuccess/studying/strategies/tests/studying

More information