Exercises Software Development I. 06 Arrays. Declaration, Initialization, Usage // Multi-dimensional Arrays. November 14, 2012
|
|
- Reynard Hunt
- 5 years ago
- Views:
Transcription
1 Exercises Software Development I 06 Arrays Declaration, Initialization, Usage // Multi-dimensional Arrays November 4, 202 Software Development I Winter term 202/203 Institute for Pervasive Computing Johannes Kepler University Linz {farrahi,riener,schmittner}@pervasive.jku.at
2 Arrays: Data Structures Problem: So far only primitive variables (int age, float value, etc.) Feasible structures for associated data needed Example: date (4..202: day, month, year) int day, month, year - this declaration does not allow to infer the relation between these variables In the given notation, a second date would be declared as int day2, month2, year2 - not very intuitive to read or use Better: The entire date should form a coherent unit 'Date' should be usable as a single parameter like a primitive variable Data structures for large number of elements Example: hotel with 500 rooms; reservation system which room is available? boolean availroom, availroom2,..., availroom500; Solution: Arrays An array is a container object that holds a fixed number of values of a single type The length of an array is established when the array is created; i.e., after creation its length is fixed Software Development I // Exercises // 06 Arrays (Declaration, Initialization, Usage; Multidim. Arrays) // 2
3 Arrays: Declaration Each item in an array is called an element, and each element is accessed by its numerical index. Example: Declare date as array of three integer values int[] date = new int[3]; // indices from 0 to 2 date[0] = 4; date[] = ; assigning values date[2] = 202; Example2: Second data array int[] date2 = new int[3]; // a second date Explicit allocation with new operator The array is of type int[] Software Development I // Exercises // 06 Arrays (Declaration, Initialization, Usage; Multidim. Arrays) // 3
4 Arrays: Allocation and Initialization Declaration and initialization can be done separately int[] date;... // data array with 3 elements (e.g., day, month, year) date = new int[3];... // not fixed; can be redeclared to store 6 elements, // e.g., day, month, year, hour, minute, second date = new int[6]; // 'old' date array: garbage collector! Initialization can be also done at declaration time int[] date = { 4,, 202 }; // length implicit, fixed int[] daysofmonth = {3, 28, 3, 30, 3, 30, 3, 3, 30, 3, 30, 3} Software Development I // Exercises // 06 Arrays (Declaration, Initialization, Usage; Multidim. Arrays) // 4
5 Arrays: References Given: 2 arrays int[] array = new int[0]; int[] array2 = new int[0]; array array What happens in case of an assignment? array2 = array; Content of array2 is lost; garbage collector cleans up memory array array Ok, both variables are of the same data type int[] Software Development I // Exercises // 06 Arrays (Declaration, Initialization, Usage; Multidim. Arrays) // 5
6 Arrays: Copying and what happens in this situation? int[] array = { 0,, 2, 3, 4, 5, 6, 7, 8, 9 }; int[] array2 = new int[0]; array array Element-wise assignment for (int i = 0; i < 0; ++i) { array2[i] = array[i]; } array array Fields of type 'int' assigned element by element Software Development I // Exercises // 06 Arrays (Declaration, Initialization, Usage; Multidim. Arrays) // 6
7 Arrays: Two-dimensional Arrays In Java, an element of an array can be itself an array Two-dimensional arrays ("matrices") int[] anarray = new int[0]; //[0]...[9] int[][] amatrix = new int[0][0]; //[0][0]..[9][9] Non-quadratic matrices are also possible (see later) Software Development I // Exercises // 06 Arrays (Declaration, Initialization, Usage; Multidim. Arrays) // 7
8 Arrays: Identity Matrix () Code to generate the identity matrix static int[][] identitymatrix(int dim) { // dim > 0 int[][] m = new int[dim][dim]; for(int row = 0; row < dim; ++row) { for(int col = 0; col < dim; ++col) { if(row == col) { } m[row][col] = ; } else { m[row][col] = 0; } } } return m; Are there more efficient ways of initialization? Use the "conditional operator (?-operator) Elements are automatically initialized with value 0 only the elements in the main diagonal need to be set to "" if(row == col) Software Development I // Exercises // 06 Arrays (Declaration, Initialization, Usage; Multidim. Arrays) // 8
9 Arrays: Multidimensional Arrays Java implements multidimensional arrays (2, 3, n dimensional) as arrays-ofarrays. This means that multidimensional arrays need not be rectangular! Example: short[][] triangle = {{}, {2, 3}, {4, 5, 6}, {7, 8, 9, 0}}; A jagged array has rows with varying number of elements Possible whenever multi-dimensioned arrays actually appear as arrays of arrays C, C++, C#, Java support jagged arrays Software Development I // Exercises // 06 Arrays (Declaration, Initialization, Usage; Multidim. Arrays) // 9
10 Arrays: Array of Objects So far we have looked at arrays of primitive types (int, float, double, etc.) But we often want to store array of objects, such as Students, Books, People, etc. Is this possible (in Java)? Sure, see later OOP Special case: Array of Strings ) Declaration of the String array private String[] strings; 2) Creation (initialization) of the array strings = new String[0]; // allocates memory to hold references to 0 String objects 3) Create String objects and add them to the array: strings[0] = new String("Hello World"); strings[i] =... Software Development I // Exercises // 06 Arrays (Declaration, Initialization, Usage; Multidim. Arrays) // 0
11 Arrays: String Arrays (Memory Organization) Example String array countries holding 0 Strings String[] countries = new String[0]; countries[0] = "Canada"; countries[5] = "Australia"; countries[9] = "Italy"; countries null Canada Australia Italy Software Development I // Exercises // 06 Arrays (Declaration, Initialization, Usage; Multidim. Arrays) //
12 Arrays: String Arrays How to use Strings in Java: String str = new String("Hello World"); int len = str.length(); // char ch = str.charat(6); // 'W String s = str.substring(3, 9); // lo Wor String t = str.replace('o', 'z'); // Hellz Wzrld boolean b = str.contains("ello"); // true int i = str.indexof('o'); // 4 int j = str.lastindexof('l'); // 9 String[] array = str.split(" "); // { Hello, World } array.length // 2 String u = array[0]; // Hello array[] = null; // { Hello, null} Software Development I // Exercises // 06 Arrays (Declaration, Initialization, Usage; Multidim. Arrays) // 2
13 Arrays: Summary () An array... Is a collection of homogeneous elements Is an object (complex data types) Is passed by reference and not by value Be careful on Assignments (=) Comparisions (==) Array parameters An array is often used to structure data (remember the date example) Most often used for a huge number of elements of the same data type (especially instead of many variables), e.g. hotel with 000 rooms: use boolean[] booked Often a better alternative is to use classes (see OOP) Software Development I // Exercises // 06 Arrays (Declaration, Initialization, Usage; Multidim. Arrays) // 3
14 Arrays: Summary (2) The length of the array needs to be known at the initialization time (latest at runtime!) length = Input.readInt(); int[] array = new int(length); This length field is a final field and cannot be changed (length is a field, not a method!) It cannot be resetted or changed by assigning a.length = 7; Arrays allows direct access to every single element Be careful with the index; runs from 0 to.length- Software Development I // Exercises // 06 Arrays (Declaration, Initialization, Usage; Multidim. Arrays) // 4
EXERCISES SOFTWARE DEVELOPMENT I. 04 Arrays & Methods 2018W
EXERCISES SOFTWARE DEVELOPMENT I 04 Arrays & Methods 2018W Solution First Test DATA TYPES, BRANCHING AND LOOPS Complete the following program, which calculates the price for a car rental. First, the program
More informationArray. Prepared By - Rifat Shahriyar
Java More Details Array 2 Arrays A group of variables containing values that all have the same type Arrays are fixed length entities In Java, arrays are objects, so they are considered reference types
More informationArrays. Arrays. Wolfgang Schreiner Research Institute for Symbolic Computation (RISC) Johannes Kepler University, Linz, Austria
Arrays Wolfgang Schreiner Research Institute for Symbolic Computation (RISC) Johannes Kepler University, Linz, Austria Wolfgang.Schreiner@risc.jku.at http://www.risc.jku.at Wolfgang Schreiner RISC Arrays
More informationExercises Software Development I. 05 Conversions and Promotions; Lifetime, Scope, Shadowing. November 5th, 2014
Exercises Software Development I 05 Conversions and Promotions; Lifetime, Scope, Shadowing November 5th, 2014 Software Development I Winter term 2014/2015 Priv.-Doz. Dipl.-Ing. Dr. Andreas Riener Institute
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 informationObject 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 informationExercises Software Development I. 08 Objects II. Generating and Releasing Objects (Constructors/Destructors, this, Object cloning) December 3rd, 2014
Exercises Software Development I 08 Objects II Generating and Releasing Objects (Constructors/Destructors, this, Object cloning) December 3rd, 2014 Software Development I Winter term 2014/2015 Priv.-Doz.
More informationCONTENTS: 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 informationChapter 9 Introduction to Arrays. Fundamentals of Java
Chapter 9 Introduction to Arrays Objectives Write programs that handle collections of similar items. Declare array variables and instantiate array objects. Manipulate arrays with loops, including the enhanced
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 informationArray. Array Declaration:
Array Arrays are continuous memory locations having fixed size. Where we require storing multiple data elements under single name, there we can use arrays. Arrays are homogenous in nature. It means and
More informationSTRUCTURED DATA TYPE ARRAYS IN C++ ONE-DIMENSIONAL ARRAY TWO-DIMENSIONAL ARRAY
STRUCTURED DATA TYPE ARRAYS IN C++ ONE-DIMENSIONAL ARRAY TWO-DIMENSIONAL ARRAY Objectives Declaration of 1-D and 2-D Arrays Initialization of arrays Inputting array elements Accessing array elements Manipulation
More informationHow to declare an array in C?
Introduction An array is a collection of data that holds fixed number of values of same type. It is also known as a set. An array is a data type. Representation of a large number of homogeneous values.
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 informationIntroduction to Programming Using Java (98-388)
Introduction to Programming Using Java (98-388) Understand Java fundamentals Describe the use of main in a Java application Signature of main, why it is static; how to consume an instance of your own class;
More informationIntroductory Programming Arrays, sections
Introductory Programming Arrays, sections 7.1-7.4 + 7.6-7.7 Anne Haxthausen a, IMM, DTU 1. What is an array? (section 7.1-2) 2. Array types. (section 7.1-2) 3. How to declare and create an array? (section
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 informationGetting started with Java
Getting started with Java by Vlad Costel Ungureanu for Learn Stuff Programming Languages A programming language is a formal constructed language designed to communicate instructions to a machine, particularly
More informationMore Arrays. Last updated 2/6/19
More Last updated 2/6/19 2 Dimensional Consider a table 1 2 3 4 5 6 5 4 3 2 12 11 13 14 15 19 17 16 3 1 4 rows x 5 columns 2 tj 2 Dimensional Consider a table 1 2 3 4 5 6 5 4 3 2 12 11 13 14 15 19 17 16
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 informationAn array is a collection of data that holds fixed number of values of same type. It is also known as a set. An array is a data type.
Data Structures Introduction An array is a collection of data that holds fixed number of values of same type. It is also known as a set. An array is a data type. Representation of a large number of homogeneous
More informationLesson 6 Introduction to Object-Oriented Programming
Lesson 6 Introduction to Object-Oriented Programming Programming Grade in Computer Engineering Outline 1. Motivation 2. Classes, objects and attributes 3. Constructors 4. Methods 5. Composition 6. Object
More informationDATA STRUCTURES CHAPTER 1
DATA STRUCTURES CHAPTER 1 FOUNDATIONAL OF DATA STRUCTURES This unit introduces some basic concepts that the student needs to be familiar with before attempting to develop any software. It describes data
More informationChapter 6: Using Arrays
Chapter 6: Using Arrays Declaring an Array and Assigning Values to Array Array Elements A list of data items that all have the same data type and the same name Each item is distinguished from the others
More informationSelected Questions from by Nageshwara Rao
Selected Questions from http://way2java.com by Nageshwara Rao Swaminathan J Amrita University swaminathanj@am.amrita.edu November 24, 2016 Swaminathan J (Amrita University) way2java.com (Nageshwara Rao)
More informationTopics. Java arrays. Definition. Data Structures and Information Systems Part 1: Data Structures. Lecture 3: Arrays (1)
Topics Data Structures and Information Systems Part 1: Data Structures Michele Zito Lecture 3: Arrays (1) Data structure definition: arrays. Java arrays creation access Primitive types and reference types
More informationManual for Basic Java
Java Boot Camp Boot Camp Manual for Basic Java By The contents of this document are the sole and exclusive property of AgileTestingAlliance.org. They may not be disclosed to any third party, copied or
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 informationLesson 9: Introduction To Arrays (Updated for Java 1.5 Modifications by Mr. Dave Clausen)
Lesson 9: Introduction To Arrays (Updated for Java 1.5 Modifications by Mr. Dave Clausen) 1 Lesson 9: Introduction Objectives: To Arrays Write programs that handle collections of similar items. Declare
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 informationLecture Notes CPSC 224 (Spring 2012) Today... Java basics. S. Bowers 1 of 8
Today... Java basics S. Bowers 1 of 8 Java main method (cont.) In Java, main looks like this: public class HelloWorld { public static void main(string[] args) { System.out.println("Hello World!"); Q: How
More informationPraktische Softwaretechnologie
Praktische Softwaretechnologie Lecture 2. Károly Bósa () Research Institute for Symbolic Computation (RISC) 1 Books James Gosling, Bill Joy, Guy Steele The JavaTM Language Specification 2 Books James Gosling,
More informationECE 122. Engineering Problem Solving with Java
ECE 122 Engineering Problem Solving with Java Lecture 5 Anatomy of a Class Outline Problem: How do I build and use a class? Need to understand constructors A few more tools to add to our toolbox Formatting
More informationCPSC 3740 Programming Languages University of Lethbridge. Data Types
Data Types A data type defines a collection of data values and a set of predefined operations on those values Some languages allow user to define additional types Useful for error detection through type
More informationData Types, Variables and Arrays. OOC 4 th Sem, B Div Prof. Mouna M. Naravani
Data Types, Variables and Arrays OOC 4 th Sem, B Div 2016-17 Prof. Mouna M. Naravani Identifiers in Java Identifiers are the names of variables, methods, classes, packages and interfaces. Identifiers must
More informationChapter 6. Arrays. Java Actually: A Comprehensive Primer in Programming
Lecture slides for: Chapter 6 Arrays Java Actually: A Comprehensive Primer in Programming Khalid Azim Mughal, Torill Hamre, Rolf W. Rasmussen Cengage Learning, 28. ISBN: 978-1-84448-933-2 http://www.ii.uib.no/~khalid/jac/
More informationLecture 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 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 information6.092: Java for 6.170
6.092: Java for 6.170 Lucy Mendel MIT EECS MIT 6.092 IAP 2006 1 Course Staff Lucy Mendel Corey McCaffrey Rob Toscano Justin Mazzola Paluska Scott Osler Ray He Ask us for help! MIT 6.092 IAP 2006 2 Class
More informationProgramming for Engineers Arrays
Programming for Engineers Arrays ICEN 200 Spring 2018 Prof. Dola Saha 1 Array Ø Arrays are data structures consisting of related data items of the same type. Ø A group of contiguous memory locations that
More informationOCA Java SE 7 Programmer I Certification Guide By Mela Gupta. Arrays
1 OCA Java SE 7 Programmer I Certification Guide By Mela Gupta In the OCA Java SE 7 programmer exam, you ll be asked many questions on how to create, modify, and delete String, StringBuilder, arrays, and
More informationArrays 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 informationModule 6: Array in C
1 Table of Content 1. Introduction 2. Basics of array 3. Types of Array 4. Declaring Arrays 5. Initializing an array 6. Processing an array 7. Summary Learning objectives 1. To understand the concept of
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 informationUNIT 3 ARRAYS, RECURSION, AND COMPLEXITY CHAPTER 10 INTRODUCTION TO ARRAYS
UNIT 3 ARRAYS, RECURSION, AND COMPLEXITY CHAPTER 10 INTRODUCTION TO ARRAYS EXERCISE 10.1 1. An array can contain many items and still be treated as one thing. Thus, instead of having many variables for
More information2. Introducing Classes
1 2. Introducing Classes Class is a basis of OOP languages. It is a logical construct which defines shape and nature of an object. Entire Java is built upon classes. 2.1 Class Fundamentals Class can be
More informationCHAPTER 7 OBJECTS AND CLASSES
CHAPTER 7 OBJECTS AND CLASSES OBJECTIVES After completing Objects and Classes, you will be able to: Explain the use of classes in Java for representing structured data. Distinguish between objects and
More informationArrays and Array Lists. CSE 1310 Introduction to Computers and Programming Vassilis Athitsos and Alexandra Stefan University of Texas at Arlington
Arrays and Array Lists CSE 1310 Introduction to Computers and Programming Vassilis Athitsos and Alexandra Stefan University of Texas at Arlington 1 Motivation Current limitation: We cannot record multiple
More informationObject Oriented Programming: In this course we began an introduction to programming from an object-oriented approach.
CMSC 131: Chapter 28 Final Review: What you learned this semester The Big Picture Object Oriented Programming: In this course we began an introduction to programming from an object-oriented approach. Java
More informationClass definition. complete definition. public public class abstract no instance can be created final class cannot be extended
JAVA Classes Class definition complete definition [public] [abstract] [final] class Name [extends Parent] [impelements ListOfInterfaces] {... // class body public public class abstract no instance can
More informationCE221 Programming in C++ Part 2 References and Pointers, Arrays and Strings
CE221 Programming in C++ Part 2 References and Pointers, Arrays and Strings 19/10/2017 CE221 Part 2 1 Variables and References 1 In Java a variable of primitive type is associated with a memory location
More informationVARIABLES AND TYPES CITS1001
VARIABLES AND TYPES CITS1001 Scope of this lecture Types in Java the eight primitive types the unlimited number of object types Values and References The Golden Rule Primitive types Every piece of data
More informationUNIT 2 ARRAYS 2.0 INTRODUCTION. Structure. Page Nos.
UNIT 2 ARRAYS Arrays Structure Page Nos. 2.0 Introduction 23 2.1 Objectives 24 2.2 Arrays and Pointers 24 2.3 Sparse Matrices 25 2.4 Polynomials 28 2.5 Representation of Arrays 30 2.5.1 Row Major Representation
More informationCS 251 Intermediate Programming Java Basics
CS 251 Intermediate Programming Java Basics Brooke Chenoweth University of New Mexico Spring 2018 Prerequisites These are the topics that I assume that you have already seen: Variables Boolean expressions
More informationArrays and ArrayLists. David Greenstein Monta Vista High School
Arrays and ArrayLists David Greenstein Monta Vista High School Array An array is a block of consecutive memory locations that hold values of the same data type. Individual locations are called array s
More informationExercises Software Development I. 03 Data Representation. Data types, range of values, internal format, literals. October 22nd, 2014
Exercises Software Development I 03 Data Representation Data types, range of values, ernal format, literals October 22nd, 2014 Software Development I Wer term 2013/2014 Priv.-Doz. Dipl.-Ing. Dr. Andreas
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 informationArrays. 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 informationJ.43 The length field of an array object makes the length of the array available. J.44 ARRAYS
ARRAYS A Java array is an Object that holds an ordered collection of elements. Components of an array can be primitive types or may reference objects, including other arrays. Arrays can be declared, allocated,
More informationLesson 06 Arrays. MIT 11053, Fundamentals of Programming By: S. Sabraz Nawaz Senior Lecturer in MIT Department of MIT FMC, SEUSL
Lesson 06 Arrays MIT 11053, Fundamentals of Programming By: S. Sabraz Nawaz Senior Lecturer in MIT Department of MIT FMC, SEUSL Array An array is a group of variables (called elements or components) containing
More informationGarbage Collection (1)
Coming up: Today: Finish unit 6 (garbage collection) start ArrayList and other library objects Wednesday: Complete ArrayList, basics of error handling Friday complete error handling Next week: Recursion
More informationArrays. Lecture 11 CGS 3416 Spring March 6, Lecture 11CGS 3416 Spring 2017 Arrays March 6, / 19
Arrays Lecture 11 CGS 3416 Spring 2017 March 6, 2017 Lecture 11CGS 3416 Spring 2017 Arrays March 6, 2017 1 / 19 Arrays Definition: An array is an indexed collection of data elements of the same type. Indexed
More informationProgramming II (CS300)
1 Programming II (CS300) Chapter 02: Using Objects MOUNA KACEM mouna@cs.wisc.edu Fall 2018 Using Objects 2 Introduction to Object Oriented Programming Paradigm Objects and References Memory Management
More informationtype arrayname [ size type arrayname [ size ] = { item ,, item size size
CMPE-3/L and Strings Gabriel Hugh Elkaim Winter 24 Definition are variables that can store many items of the same type. The individual items known as elements, are stored sequentially and are uniquely
More informationDeclarations and Access Control SCJP tips
Declarations and Access Control www.techfaq360.com SCJP tips Write code that declares, constructs, and initializes arrays of any base type using any of the permitted forms both for declaration and for
More informationProblems with simple variables
Problems with simple variables Hard to give up values high number of variables. Complex to sort a high number of variables by value. Impossible to use loops. Example problem: Read one hundred numbers,
More informationC# and Java. C# and Java are both modern object-oriented languages
C# and Java C# and Java are both modern object-oriented languages C# came after Java and so it is more advanced in some ways C# has more functional characteristics (e.g., anonymous functions, closure,
More informationArrays 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 informationCSC207H: Software Design. Java + OOP. CSC207 Winter 2018
Java + OOP CSC207 Winter 2018 1 Why OOP? Modularity: code can be written and maintained separately, and easily passed around the system Information-hiding: internal representation hidden from the outside
More informationClass definition. complete definition. public public class abstract no instance can be created final class cannot be extended
JAVA Classes Class definition complete definition [public] [abstract] [final] class Name [extends Parent] [impelements ListOfInterfaces] {... // class body public public class abstract no instance can
More information6. Pointers, Structs, and Arrays. 1. Juli 2011
1. Juli 2011 Einführung in die Programmierung Introduction to C/C++, Tobias Weinzierl page 1 of 50 Outline Recapitulation Pointers Dynamic Memory Allocation Structs Arrays Bubble Sort Strings Einführung
More informationSTUDENT LESSON A10 The String Class
STUDENT LESSON A10 The String Class Java Curriculum for AP Computer Science, Student Lesson A10 1 STUDENT LESSON A10 The String Class INTRODUCTION: Strings are needed in many programming tasks. Much of
More informationUNIT 6. STRUCTURED DATA TYPES PART 1: ARRAYS
UNIT 6. STRUCTURED DATA TYPES PART 1: ARRAYS Programming Year 2017-2018 Industrial Technology Engineering Paula de Toledo Contents 1. Structured data types vs simple data types 2. Arrays (vectors and matrices)
More informationLecture 13: Complex Types and Garbage Collection
Lecture 13: Complex Types and Garbage Collection COMP 524 Programming Language Concepts Stephen Olivier March 17, 2009 Based on slides by A. Block, notes by N. Fisher, F. Hernandez-Campos, and D. Stotts
More informationFor instance, we can declare an array of five ints like this: int numbers[5];
CIT 593 Intro to Computer Systems Lecture #17 (11/13/12) Arrays An array is a collection of values. In C, as in many other languages: all elements of the array must be of the same type the number of elements
More informationGabriel Hugh Elkaim Spring CMPE 013/L: C Programming. CMPE 013/L: C Programming
1 2 3 CMPE 013/L and Strings Gabriel Hugh Elkaim Spring 2013 4 Definition are variables that can store many items of the same type. The individual items known as elements, are stored sequentially and are
More informationInstructor: 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 informationCSC207H: Software Design. Java + OOP. CSC207 Winter 2018
Java + OOP CSC207 Winter 2018 1 Why OOP? Modularity: code can be written and maintained separately, and easily passed around the system Information-hiding: internal representation hidden from the outside
More informationArrays 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 informationChapter 8 :: Composite Types
Chapter 8 :: Composite Types Programming Language Pragmatics, Fourth Edition Michael L. Scott Copyright 2016 Elsevier 1 Chapter08_Composite_Types_4e - Tue November 21, 2017 Records (Structures) and Variants
More informationDynamic Memory Allocation
Dynamic Memory Allocation Lecture 15 COP 3014 Fall 2017 November 6, 2017 Allocating memory There are two ways that memory gets allocated for data storage: 1. Compile Time (or static) Allocation Memory
More informationArrays & Linked Lists
Arrays & Linked Lists Part 1: Arrays Array Definition An array is a sequenced collection of variables all of the same type. Each variable, or cell, in an array has an index, which uniquely refers to the
More informationPROGRAMMAZIONE I A.A. 2017/2018
PROGRAMMAZIONE I A.A. 2017/2018 ARRAYS ARRAYS An array contains objects of a given type, stored consecutively in a continuous memory block. The individual objects are called the elements of an array. The
More informationSPRING 13 CS 0007 FINAL EXAM V2 (Roberts) Your Name: A pt each. B pt each. C pt each. D or 2 pts each
Your Name: Your Pitt (mail NOT peoplesoft) ID: Part Question/s Points available Rubric Your Score A 1-6 6 1 pt each B 7-12 6 1 pt each C 13-16 4 1 pt each D 17-19 5 1 or 2 pts each E 20-23 5 1 or 2 pts
More informationJava Arrays. What could go wrong here? Motivation. Array Definition 9/28/18. Mohammad Ghafari
9/28/8 Java Arrays What could go wrong here? int table[][] = new int[2][]; // some code int sum = ; for (int i = ; i < 2; i++) for (int j = ; j < ; j++) int value = table[i][j]; sum += value; Mohammad
More informationCSC Java Programming, Fall Java Data Types and Control Constructs
CSC 243 - Java Programming, Fall 2016 Java Data Types and Control Constructs Java Types In general, a type is collection of possible values Main categories of Java types: Primitive/built-in Object/Reference
More informationCS 177 Week 15 Recitation Slides. Review
CS 177 Week 15 Recitation Slides Review 1 Announcements Final Exam on Friday Dec. 18 th STEW 183 from 1 3 PM Complete your online review of your classes. Your opinion matters!!! Project 6 due Just kidding
More informationLesson 7. Reading and Writing a.k.a. Input and Output
Lesson 7 Reading and Writing a.k.a. Input and Output Escape sequences for printf strings Source: http://en.wikipedia.org/wiki/escape_sequences_in_c Escape sequences for printf strings Why do we need escape
More informationModern Programming Languages. Lecture Java Programming Language. An Introduction
Modern Programming Languages Lecture 27-30 Java Programming Language An Introduction 107 Java was developed at Sun in the early 1990s and is based on C++. It looks very similar to C++ but it is significantly
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 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 informationSchool of Computer Science CPS109 Course Notes Set 7 Alexander Ferworn Updated Fall 15 CPS109 Course Notes 7
CPS109 Course Notes 7 Alexander Ferworn Unrelated Facts Worth Remembering The most successful people in any business are usually the most interesting. Don t confuse extensive documentation of a situation
More information6. Pointers, Structs, and Arrays. March 14 & 15, 2011
March 14 & 15, 2011 Einführung in die Programmierung Introduction to C/C++, Tobias Weinzierl page 1 of 47 Outline Recapitulation Pointers Dynamic Memory Allocation Structs Arrays Bubble Sort Strings Einführung
More informationECE 122. Engineering Problem Solving with Java
ECE 122 Engineering Problem Solving with Java Lecture 13 Two Dimensional Arrays Outline Problem: How do store and manipulate data in tabular format Two-dimensional arrays easy access with 2 indices This
More informationECE 122. Engineering Problem Solving with Java
ECE 122 Engineering Problem Solving with Java Lecture 13 Two Dimensional Arrays Outline Problem: How do store and manipulate data in tabular format Two-dimensional arrays easy access with 2 indices This
More informationIntroduce C# as Object Oriented programming language. Explain, tokens,
Module 2 98 Assignment 1 Introduce C# as Object Oriented programming language. Explain, tokens, lexicals and control flow constructs. 99 The C# Family Tree C Platform Independence C++ Object Orientation
More information1B1a Arrays. Arrays. Indexing. Naming arrays. Why? Using indexing. 1B1a Lecture Slides. Copyright 2003, Graham Roberts 1
Ba Arrays Arrays A normal variable holds value: An array variable holds a collection of values: 4 Naming arrays An array has a single name, so the elements are numbered or indexed. 0 3 4 5 Numbering starts
More information1007 Imperative Programming Part II
Agenda 1007 Imperative Programming Part II We ve seen the basic ideas of sequence, iteration and selection. Now let s look at what else we need to start writing useful programs. Details now start to be
More informationArrays. int Data [8] [0] [1] [2] [3] [4] [5] [6] [7]
Arrays Arrays deal with storage of data, which can be processed later. Arrays are a series of elements (variables) of the same type placed consecutively in memory that can be individually referenced by
More informationCS 430 Spring Mike Lam, Professor. Data Types and Type Checking
CS 430 Spring 2015 Mike Lam, Professor Data Types and Type Checking Type Systems Type system Rules about valid types, type compatibility, and how data values can be used Benefits of a robust type system
More information