CSE 21 Intro to Computing II. JAVA Objects: String & Scanner

Size: px
Start display at page:

Download "CSE 21 Intro to Computing II. JAVA Objects: String & Scanner"

Transcription

1 CSE 21 Intro to Computing II JAVA Objects: String & Scanner 1

2 Schedule to Semester s End Week of 11/05 - Lecture #8 (11/07), Lab #10 Week of 11/12 - Lecture #9 (11/14), Lab #11, Project #2 Opens Week of 11/19 - Lecture Review (11/21), NO LAB Week of 11/26 - Lecture #11 (11/28), Lab #12 Week of 12/03 - Final Review, Lab #13, Project #2 Due Final Exam: December 12 th from 3:00 to 6:00pm Project #1 Available on Friday November 16 th at 11:55pm Due on Monday December 3 rd at 11:55pm Work alone or in a team of 2 Every student must submit the project Worth 7.5% of your overall grade Understanding Lecture Concepts Code samples: UCMCROPS->Resources->CodeSamples 2

3 Class String A string is an object containing one or more characters, treated as a unit. Strings are objects. You can think of them as classes that are already available for you to use. The simplest way to create a string is a string literal, which is a series of characters between quotation marks. Example: This is a string literal. You have already used string literals inside print statements. 3

4 Creating Strings To create a String: First, declare a String object (this is the same way you would declare another data type). Then, assign the String using a string literal or the new operator. Examples: String s1, s2; // Create two String objects s1 = "This is a test."; // Assign to String Literal s2 = new String(); // Create a blank string These steps can be combined on a single line: String s3 = "String 3."; // All together 4

5 Strings are Very much like arrays! Think of a String as an array of characters Examples: String s1 = Test"; char [] s2 = { C, S, E, 2, 1 }; Accessing characters of the String is done using the charat function (instead of []) Examples: System.out.println(s1.charAt(0) + + s1.charat(1)); System.out.println(s2[0] + + s2[1]); Output: T e C S 5

6 Strings == arrays of chars! Indices start with 0 Function length()returns the number of chars String astring = new String(); int [] anarray = new int[]; astring.length() // We call a the function length() anarray.length // We get the variable length() Each character is defined by a code (or number) that represents one character The ASCII table defines these codes ASCII stands for American Standard Code for Information Interchange 6

7 The ASCII table 7

8 Example of ASCII codes String str = aabcdbcd ; System.out.println(str.charAt(0)); System.out.println((int)str.charAt(0)); for(int i=0; i<str.length(); i++) System.out.print((int)str.charAt(i) +, ); Output a 97 97,65,98,99,100,66,67,68 Note: different codes for upper and lower case! A!= a 8

9 Comparing String characters We can still use the charat method to get the character Checking if two String are the same String s1 = my string ; String s2 = my string ; if(s1.length()!= s2.length()) System.out.println( NO ); else { for(int i = 0; i < s1.length() ; i++) if( s1.charat(i)!= s2.charat(i)) { System.out.println( NO ); return; } System.out.println( YES );} ASCII codes are used for comparison if (s1.charat(i) == + ) // Checks of character i is + if (s1.charat(i) <= Z && s1.charat(i) >= A ) // If char i is A-Z if (s1.charat(i) <= z && s1.charat(i) >= a ) // If char i is a-z 9

10 Strings work like other Objects new operator allows us to create objects: String s1 = new String; int [] a = new int[]; We manipulate objects with variables that represent the objects! s1 and a are variable names for a String and an array (of int)! We access functions of objects using the member access (dot) operator sharp.getname(); sharp.setamount(input.nextint()); We can also access String functions using the member access (dot) operator: String s1 = my string ; s1.charat(2); 10

11 Useful Function: Substring A substring is a portion of a String. The String function substring creates a new String object containing a portion of another String. The function can be called two different ways: s.substring(int startindex); // From <start> to s.length() s.substring(int startindex, int endindex);// <start> to <end> NOTE: IT DOES NOT INCLUDE endindex! This method returns another String object containing the characters from start to end (or the end of the string). 11

12 Substring Example Examples: String s = "abcdefgh"; String s1 = s.substring(3); String s2 = s.substring(3,6); String s3 = s.substring(1,3); String s4 = s2.substring(1,2); Substring s1 contains "defgh", and substring s2 contains "def". Substring s4 is assigned a substring of s2 Reminder: indices start at 0 s1 s3 s "defgh" "abcdefgh" s.substring(3) s.substring(3,6) bc" s2 "def" s4 "e" 12

13 Useful Function: Concat The String function concat creates a new String object containing the contents of two strings. The form of this function is: s1.concat(string s2); // Combine s1 and s2 This method returns a String object containing the contents of s1 followed by the contents of s2. 13

14 Concatenating Strings: Example Example: String s1 = "abc"; String s2 = def ; System.out.println(s1); System.out.println(s2); String s3 = s1.concat(s2); String s4 = s2.concat(s1); System.out.println(s1); System.out.println(s2); System.out.println(s3); System.out.println(s4); Output: abc def abc def abcdef defabc 14

15 Using + for Concatenation Example: String s1 = "abc"; String s2 = def ; System.out.println(s1); System.out.println(s2); String s3 = s1 + s2; // This was s1.concat(s2) String s4 = s2 + s1; // This was s2.concat(s1) System.out.println(s1); System.out.println(s2); System.out.println(s3); System.out.println(s4); Output: abc def abc def abcdef defabc 15

16 Selected Additional String Methods 16

17 Scanners Read from User: Scanner kdb = new Scanner (System.in); Pass System.in as parameter to Scanner constructor You can also pass a string as a parameter String example = This is an example ; Scanner line = new Scanner (example); Scanner Functions: next() kdb.next(); line.next(); // get next input word from keyboard // get next input word from string example Scanner Functions: hasnext() line.hasnext() ; check if there is another word in string example Returns a Boolean value (true or false)

18 Using Scanners to Parse Strings String example = This is an example ; Scanner line= new Scanner (example); while (line.hasnext()) { System.out.println(line.next()); } Note: delimiting character is a space ( ) be default next() function will look for a word until deliminating character is found OUTPUT This is an example

19 Parsing Strings with Delimiter String example = This,is,an example, with custom,delimiter ; Scanner line = new Scanner (example); line.usedelimiter( [,] ); // Tell scanner to use, as the delimiter while (line.hasnext()) { System.out.println(line.next()); } Delimiting character is comma, NOT a space:, OUTPUT This is an example with custom delimiter

20 Multiple Delimit Characters String example = + This,is+ an,example ; Scanner input = new Scanner (example); input.usedelimiter( [,+] ); while (input.hasnext()) { System.out.println(input.next()); } Delimiting characters are comma and plus :, + OUTPUT: This is an example

21 Reading/Processing Files import java.io.*; // Top of your file String filename = nums.txt ; Scanner input = new Scanner (new FileReader(filename)); input.usedelimiter( [\r] ); // use tab and carriage return while (input.hasnext()) { System.out.println(input.next()); } input.close(); This code segment reads a file and outputs its contents line by line Exceptions must be handled when reading files: FileNotFoundException NoSuchElementException

22 Reading a CSV file import java.io.*; System.out.print("Enter the file name: "); Scanner kdb = new Scanner(System.in); String filename = kdb.next(); try { // TRY it out Scanner input = new Scanner (new FileReader(filename)); while (input.hasnextline()) { Scanner line = new Scanner(input.nextLine()); line.usedelimiter( [,] ); // Tab delimited file while (line.hasnext()){ System.out.print(line.next()); // Read each token System.out.println(); // Done reading one line } } input.close(); } catch (FileNotFoundException e){ // Catch error System.out.println( File could not be found ); } catch (NoSuchElementException e) { // Catch error System.out.println( Tried to use next, with nothing to get ); }

23 Different Scanner Functions while (input.hasnextline()) { Scanner line = new Scanner(input.nextLine()); line.setdelimiter( [\t\r] ); short s = line.nextshort(); int i = line.nextint(); double d = line.nextdouble(); float f = line.nextfloat(); String str = line.next(); char c = line.next().charat(0); String rest = line.nextline(); } 23

24 Filenames and Paths String s; s = myfile.txt ; // in current folder s =../myfile.txt ; // previous folder // (relative path) s = C:/tmp/myfile.txt ; // full path specified s = C:\temp-file.txt ; // Error! (\t is a tab!) s = C:\\tmp\\myfile.txt ; // Ok in windows Scanner input = new Scanner (new FileReader(s)); 24

CSE 21 Intro to Computing II. Inheritance

CSE 21 Intro to Computing II. Inheritance CSE 21 Intro to Computing II Inheritance 1 Administrative Business Lab11 (this week) is due on November 27 th extension Extra lab section on Tuesday November 20 th from 3-6pm (SE138) No lab November 20/23

More information

CSE 21 Intro to Computing II. Post-Midterm Review

CSE 21 Intro to Computing II. Post-Midterm Review CSE 21 Intro to Computing II Post-Midterm Review 1 Post-Midterm Review Topics Object Oriented Programming Classes Inheritance String/File Manipulation String functions (substr, concat, +) Scanner functions

More information

Today s plan Discuss the Bb quiz 1 Clarify Lab 1 Review basic Java materials Classes, Objects, Interfaces Strings Java IO. Understanding Board

Today s plan Discuss the Bb quiz 1 Clarify Lab 1 Review basic Java materials Classes, Objects, Interfaces Strings Java IO. Understanding Board Ananda Gunawardena Today s plan Discuss the Bb quiz 1 Clarify Lab 1 Review basic Java materials Classes, Objects, Interfaces Strings Java IO Lab 1 Objectives Learn how to structure TicTacToeprogram as

More information

Any serious Java programmers should use the APIs to develop Java programs Best practices of using APIs

Any serious Java programmers should use the APIs to develop Java programs Best practices of using APIs Ananda Gunawardena Java APIs Think Java API (Application Programming Interface) as a super dictionary of the Java language. It has a list of all Java packages, classes, and interfaces; along with all of

More information

Programming with Java

Programming with Java Programming with Java Data Types & Input Statement Lecture 04 First stage Software Engineering Dep. Saman M. Omer 2017-2018 Objectives q By the end of this lecture you should be able to : ü Know rules

More information

Today s plan Discuss the Lab 1 Show Lab 2 Review basic Java materials Java API Strings Java IO

Today s plan Discuss the Lab 1 Show Lab 2 Review basic Java materials Java API Strings Java IO Today s plan Discuss the Lab 1 Show Lab 2 Review basic Java materials Java API Strings Java IO Ananda Gunawardena Objects and Methods working together to solve a problem Object Oriented Programming Paradigm

More information

CS 101 Exam 1 Spring 200 Id Name

CS 101 Exam 1 Spring 200  Id Name This exam is open text book and closed notes. Different questions have different points associated with them with later occurring questions having more worth than the beginning questions. Because your

More information

Full file at

Full file at Chapter 1 Primitive Java Weiss 4 th Edition Solutions to Exercises (US Version) 1.1 Key Concepts and How To Teach Them This chapter introduces primitive features of Java found in all languages such as

More information

Simple Java Input/Output

Simple Java Input/Output Simple Java Input/Output Prologue They say you can hold seven plus or minus two pieces of information in your mind. I can t remember how to open files in Java. I ve written chapters on it. I ve done it

More information

Introduction to Computer Programming

Introduction to Computer Programming Introduction to Computer Programming Lecture #8 - Stringing Along Using Character and String Data How Do Computer Handle Character Data? Like all other data that a computer handles, characters are stored

More information

Programming with Java

Programming with Java Programming with Java String & Making Decision Lecture 05 First stage Software Engineering Dep. Saman M. Omer 2017-2018 Objectives By the end of this lecture you should be able to : Understand another

More information

COMP200 INPUT/OUTPUT. OOP using Java, based on slides by Shayan Javed

COMP200 INPUT/OUTPUT. OOP using Java, based on slides by Shayan Javed 1 1 COMP200 INPUT/OUTPUT OOP using Java, based on slides by Shayan Javed Input/Output (IO) 2 3 I/O So far we have looked at modeling classes 4 I/O So far we have looked at modeling classes Not much in

More information

Full file at

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

Lecture 6. Assignments. Java Scanner. User Input 1/29/18. Reading: 2.12, 2.13, 3.1, 3.2, 3.3, 3.4

Lecture 6. Assignments. Java Scanner. User Input 1/29/18. Reading: 2.12, 2.13, 3.1, 3.2, 3.3, 3.4 Assignments Reading: 2.12, 2.13, 3.1, 3.2, 3.3, 3.4 Lecture 6 Complete for Lab 4, Project 1 Note: Slides 12 19 are summary slides for Chapter 2. They overview much of what we covered but are not complete.

More information

CS 180. Recitation 8 / {30, 31} / 2007

CS 180. Recitation 8 / {30, 31} / 2007 CS 180 Recitation 8 / 30, 31 / 2007 Announcements Project 1 is out Due 9/5 @ 10:00pm Start early! Use the newsgroup for your questions LWSN B146 Lab help hours 7-10pm Monday through Wednesday Naming Conventions

More information

Lecture Set 2: Starting Java

Lecture Set 2: Starting Java Lecture Set 2: Starting Java 1. Java Concepts 2. Java Programming Basics 3. User output 4. Variables and types 5. Expressions 6. User input 7. Uninitialized Variables 0 This Course: Intro to Procedural

More information

Lecture Set 2: Starting Java

Lecture Set 2: Starting Java Lecture Set 2: Starting Java 1. Java Concepts 2. Java Programming Basics 3. User output 4. Variables and types 5. Expressions 6. User input 7. Uninitialized Variables 0 This Course: Intro to Procedural

More information

Java s String Class. in simplest form, just quoted text. used as parameters to. "This is a string" "So is this" "hi"

Java s String Class. in simplest form, just quoted text. used as parameters to. This is a string So is this hi 1 Java s String Class in simplest form, just quoted text "This is a string" "So is this" "hi" used as parameters to Text constructor System.out.println 2 The Empty String smallest possible string made

More information

Intro to Computer Science II

Intro to Computer Science II Intro to Computer Science II CS112-2012S-04 Strings David Galles Department of Computer Science University of San Francisco 04-0: Types in Java Primative Types Hold simple values Can be stored on the stack

More information

Lecture 6. Assignments. Summary - Variables. Summary Program Parts 1/29/18. Reading: 3.1, 3.2, 3.3, 3.4

Lecture 6. Assignments. Summary - Variables. Summary Program Parts 1/29/18. Reading: 3.1, 3.2, 3.3, 3.4 Assignments Lecture 6 Complete for Project 1 Reading: 3.1, 3.2, 3.3, 3.4 Summary Program Parts Summary - Variables Class Header (class name matches the file name prefix) Class Body Because this is a program,

More information

what are strings today: strings strings: output strings: declaring and initializing what are strings and why to use them reading: textbook chapter 8

what are strings today: strings strings: output strings: declaring and initializing what are strings and why to use them reading: textbook chapter 8 today: strings what are strings what are strings and why to use them reading: textbook chapter 8 a string in C++ is one of a special kind of data type called a class we will talk more about classes in

More information

MIDTERM REVIEW. midterminformation.htm

MIDTERM REVIEW.   midterminformation.htm MIDTERM REVIEW http://pages.cpsc.ucalgary.ca/~tamj/233/exams/ midterminformation.htm 1 REMINDER Midterm Time: 7:00pm - 8:15pm on Friday, Mar 1, 2013 Location: ST 148 Cover everything up to the last lecture

More information

We now start exploring some key elements of the Java programming language and ways of performing I/O

We now start exploring some key elements of the Java programming language and ways of performing I/O We now start exploring some key elements of the Java programming language and ways of performing I/O This week we focus on: Introduction to objects The String class String concatenation Creating objects

More information

A variable is a name for a location in memory A variable must be declared

A variable is a name for a location in memory A variable must be declared Variables A variable is a name for a location in memory A variable must be declared, specifying the variable's name and the type of information that will be held in it data type variable name int total;

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

Full file at

Full file at Java Programming, Fifth Edition 2-1 Chapter 2 Using Data within a Program At a Glance Instructor s Manual Table of Contents Overview Objectives Teaching Tips Quick Quizzes Class Discussion Topics Additional

More information

Chapter 12 Strings and Characters. Dr. Hikmat Jaber

Chapter 12 Strings and Characters. Dr. Hikmat Jaber Chapter 12 Strings and Characters Dr. Hikmat Jaber 1 The String Class Constructing a String: String message = "Welcome to Java ; String message = new String("Welcome to Java ); String s = new String();

More information

Software Practice 1 - File I/O

Software Practice 1 - File I/O Software Practice 1 - File I/O Stream I/O Buffered I/O File I/O with exceptions CSV format Practice#6 Prof. Joonwon Lee T.A. Jaehyun Song Jongseok Kim (42) T.A. Sujin Oh Junseong Lee 1 (43) / 38 2 / 38

More information

ECE 122 Engineering Problem Solving with Java

ECE 122 Engineering Problem Solving with Java ECE 122 Engineering Problem Solving with Java Lecture 3 Expression Evaluation and Program Interaction Outline Problem: How do I input data and use it in complicated expressions Creating complicated expressions

More information

Chapter 2 Using Data. Instructor s Manual Table of Contents. At a Glance. Overview. Objectives. Teaching Tips. Quick Quizzes. Class Discussion Topics

Chapter 2 Using Data. Instructor s Manual Table of Contents. At a Glance. Overview. Objectives. Teaching Tips. Quick Quizzes. Class Discussion Topics Java Programming, Sixth Edition 2-1 Chapter 2 Using Data At a Glance Instructor s Manual Table of Contents Overview Objectives Teaching Tips Quick Quizzes Class Discussion Topics Additional Projects Additional

More information

Chapter 2 Part 2 Edited by JJ Shepherd, James O Reilly

Chapter 2 Part 2 Edited by JJ Shepherd, James O Reilly Basic Computation Chapter 2 Part 2 Edited by JJ Shepherd, James O Reilly Parentheses and Precedence Parentheses can communicate the order in which arithmetic operations are performed examples: (cost +

More information

CMPSCI 187: Programming With Data Structures. Lecture #24: Files and a Case Study David Mix Barrington 2 November 2012

CMPSCI 187: Programming With Data Structures. Lecture #24: Files and a Case Study David Mix Barrington 2 November 2012 CMPSCI 187: Programming With Data Structures Lecture #24: Files and a Case Study David Mix Barrington 2 November 2012 Files and a Case Study Volatile and Non-Volatile Storage Storing and Retrieving Objects

More information

boolean, char, class, const, double, else, final, float, for, if, import, int, long, new, public, return, static, throws, void, while

boolean, char, class, const, double, else, final, float, for, if, import, int, long, new, public, return, static, throws, void, while CSCI 150 Fall 2007 Java Syntax The following notes are meant to be a quick cheat sheet for Java. It is not meant to be a means on its own to learn Java or this course. For that you should look at your

More information

The Irving K. Barber School of Arts and Sciences COSC 111 Final Exam Winter Term II Instructor: Dr. Bowen Hui. Tuesday, April 19, 2016

The Irving K. Barber School of Arts and Sciences COSC 111 Final Exam Winter Term II Instructor: Dr. Bowen Hui. Tuesday, April 19, 2016 First Name (Print): Last Name (Print): Student Number: The Irving K. Barber School of Arts and Sciences COSC 111 Final Exam Winter Term II 2016 Instructor: Dr. Bowen Hui Tuesday, April 19, 2016 Time: 6:00pm

More information

String related classes

String related classes Java Strings String related classes Java provides three String related classes java.lang package String class: Storing and processing Strings but Strings created using the String class cannot be modified

More information

CS1150 Principles of Computer Science Math Functions, Characters and Strings (Part II)

CS1150 Principles of Computer Science Math Functions, Characters and Strings (Part II) CS1150 Principles of Computer Science Math Functions, Characters and Strings (Part II) Yanyan Zhuang Department of Computer Science http://www.cs.uccs.edu/~yzhuang CS1150 UC. Colorado Springs How to generate

More information

Assoc. Prof. Marenglen Biba. (C) 2010 Pearson Education, Inc. All rights reserved.

Assoc. Prof. Marenglen Biba. (C) 2010 Pearson Education, Inc. All rights reserved. Assoc. Prof. Marenglen Biba (C) 2010 Pearson Education, Inc. All This chapter discusses class String, from the java.lang package. These classes provide the foundation for string and character manipulation

More information

5/29/2006. Announcements. Last Time. Today. Text File I/O Sample Programs. The File Class. Without using FileReader. Reviewed method overloading.

5/29/2006. Announcements. Last Time. Today. Text File I/O Sample Programs. The File Class. Without using FileReader. Reviewed method overloading. Last Time Reviewed method overloading. A few useful Java classes: Other handy System class methods Wrapper classes String class StringTokenizer class Assn 3 posted. Announcements Final on June 14 or 15?

More information

First Java Program - Output to the Screen

First Java Program - Output to the Screen First Java Program - Output to the Screen These notes are written assuming that the reader has never programmed in Java, but has programmed in another language in the past. In any language, one of the

More information

Week 12. Streams and File I/O. Overview of Streams and File I/O Text File I/O

Week 12. Streams and File I/O. Overview of Streams and File I/O Text File I/O Week 12 Streams and File I/O Overview of Streams and File I/O Text File I/O 1 I/O Overview I/O = Input/Output In this context it is input to and output from programs Input can be from keyboard or a file

More information

Language Reference Manual

Language Reference Manual TAPE: A File Handling Language Language Reference Manual Tianhua Fang (tf2377) Alexander Sato (as4628) Priscilla Wang (pyw2102) Edwin Chan (cc3919) Programming Languages and Translators COMSW 4115 Fall

More information

H212 Introduction to Software Systems Honors

H212 Introduction to Software Systems Honors Introduction to Software Systems Honors Lecture #04: Fall 2015 1/20 Office hours Monday, Wednesday: 10:15 am to 12:00 noon Tuesday, Thursday: 2:00 to 3:45 pm Office: Lindley Hall, Room 401C 2/20 Printing

More information

Assoc. Prof. Marenglen Biba. (C) 2010 Pearson Education, Inc. All rights reserved.

Assoc. Prof. Marenglen Biba. (C) 2010 Pearson Education, Inc. All rights reserved. Assoc. Prof. Marenglen Biba (C) 2010 Pearson Education, Inc. All Advanced Java This chapter discusses class String, class StringBuilder and class Character from the java.lang package. These classes provide

More information

Using Java Classes Fall 2018 Margaret Reid-Miller

Using Java Classes Fall 2018 Margaret Reid-Miller Using Java Classes 15-121 Fall 2018 Margaret Reid-Miller Today Strings I/O (using Scanner) Loops, Conditionals, Scope Math Class (random) Fall 2018 15-121 (Reid-Miller) 2 The Math Class The Math class

More information

Mid Term Exam 1. Programming I (CPCS 202) Instructor: M. G. Abbas Malik Date: Sunday November 3, 2013 Total Marks: 50 Obtained Marks:

Mid Term Exam 1. Programming I (CPCS 202) Instructor: M. G. Abbas Malik Date: Sunday November 3, 2013 Total Marks: 50 Obtained Marks: Mid Term Exam 1 Programming I (CPCS 202) Instructor: M. G. Abbas Malik Date: Sunday November 3, 2013 Student Name: Total Marks: 50 Obtained Marks: Instructions: Do not open this exam booklet until you

More information

Classes Basic Overview

Classes Basic Overview Final Review!!! Classes and Objects Program Statements (Arithmetic Operations) Program Flow String In-depth java.io (Input/Output) java.util (Utilities) Exceptions Classes Basic Overview A class is a container

More information

COMP String and Console I/O. Yi Hong May 18, 2015

COMP String and Console I/O. Yi Hong May 18, 2015 COMP 110-001 String and Console I/O Yi Hong May 18, 2015 Announcements Labs 0 & 1 are due today by 11:59pm Homework 0 grades are posted Office hours are fixed: MW 3-4pm, or by appointment Review of How

More information

CSCI 2010 Principles of Computer Science. Data and Expressions 08/09/2013 CSCI

CSCI 2010 Principles of Computer Science. Data and Expressions 08/09/2013 CSCI CSCI 2010 Principles of Computer Science Data and Expressions 08/09/2013 CSCI 2010 1 Data Types, Variables and Expressions in Java We look at the primitive data types, strings and expressions that are

More information

CSEN202: Introduction to Computer Science Spring Semester 2017 Midterm Exam

CSEN202: Introduction to Computer Science Spring Semester 2017 Midterm Exam Page 0 German University in Cairo April 6, 2017 Media Engineering and Technology Faculty Prof. Dr. Slim Abdennadher CSEN202: Introduction to Computer Science Spring Semester 2017 Midterm Exam Bar Code

More information

Java Input/Output. 11 April 2013 OSU CSE 1

Java Input/Output. 11 April 2013 OSU CSE 1 Java Input/Output 11 April 2013 OSU CSE 1 Overview The Java I/O (Input/Output) package java.io contains a group of interfaces and classes similar to the OSU CSE components SimpleReader and SimpleWriter

More information

Introducing arrays. Week 4: arrays and strings. Creating arrays. Declaring arrays. Initialising arrays. Declaring and creating in one step

Introducing arrays. Week 4: arrays and strings. Creating arrays. Declaring arrays. Initialising arrays. Declaring and creating in one step School of Computer Science, University of Birmingham Java Lecture notes. M. D. Ryan. September 2001. Introducing arrays Week 4: arrays and strings Arrays: a data structure used to store multiple data,

More information

Midterms Save the Dates!

Midterms Save the Dates! University of British Columbia CPSC 111, Intro to Computation Alan J. Hu (Using the Scanner and String Classes) Anatomy of a Java Program Readings This Week s Reading: Ch 3.1-3.8 (Major conceptual jump

More information

Computer Science 145 Midterm 1 Fall 2016

Computer Science 145 Midterm 1 Fall 2016 Computer Science 145 Midterm 1 Fall 2016 Doodle here. This is a closed-book, no-calculator, no-electronic-devices, individual-effort exam. You may reference one page of handwritten notes. All answers should

More information

CISC-124. This week we continued to look at some aspects of Java and how they relate to building reliable software.

CISC-124. This week we continued to look at some aspects of Java and how they relate to building reliable software. CISC-124 20180129 20180130 20180201 This week we continued to look at some aspects of Java and how they relate to building reliable software. Multi-Dimensional Arrays Like most languages, Java permits

More information

CSE 1223: Exam II Autumn 2016

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

Notes from the Boards Set BN19 Page

Notes from the Boards Set BN19 Page 1 The Class, String There are five programs in the class code folder Set17. The first one, String1 is discussed below. The folder StringInput shows simple string input from the keyboard. Processing is

More information

COMP-202: Foundations of Programming. Lecture 12: Linked List, and File I/O Sandeep Manjanna, Summer 2015

COMP-202: Foundations of Programming. Lecture 12: Linked List, and File I/O Sandeep Manjanna, Summer 2015 COMP-202: Foundations of Programming Lecture 12: Linked List, and File I/O Sandeep Manjanna, Summer 2015 Announcements Assignment 4 is posted and Due on 29 th of June at 11:30 pm. Course Evaluations due

More information

Place your name tag here

Place your name tag here CS 170 Exam 1 Section 001 Spring 2015 Name: Place your name tag here Instructions: Keep your eyes on your own paper and do your best to prevent anyone else from seeing your work. Do NOT communicate with

More information

Strings in Java String Methods. The only operator that can be applied to String objects is concatenation (+) for combining one or more strings.

Strings in Java String Methods. The only operator that can be applied to String objects is concatenation (+) for combining one or more strings. The only operator that can be applied to String objects is concatenation (+) for combining one or more strings. Java also provides many methods with the String class to allow us to manipulate text. These

More information

CSE 113 A. Announcements - Lab

CSE 113 A. Announcements - Lab CSE 113 A February 21-25, 2011 Announcements - Lab Lab 1, 2, 3, 4; Practice Assignment 1, 2, 3, 4 grades are available in Web-CAT look under Results -> Past Results and if looking for Lab 1, make sure

More information

Strings, Arrays, A1. COMP 401, Spring 2015 Lecture 4 1/20/2015

Strings, Arrays, A1. COMP 401, Spring 2015 Lecture 4 1/20/2015 Strings, Arrays, A1 COMP 401, Spring 2015 Lecture 4 1/20/2015 Java Execu@on Model Your program is always execu@ng within the context of some method. Starts off in the main class method defined in whatever

More information

COMP 202. Built in Libraries and objects. CONTENTS: Introduction to objects Introduction to some basic Java libraries string

COMP 202. Built in Libraries and objects. CONTENTS: Introduction to objects Introduction to some basic Java libraries string COMP 202 Built in Libraries and objects CONTENTS: Introduction to objects Introduction to some basic Java libraries string COMP 202 Objects and Built in Libraries 1 Classes and Objects An object is an

More information

UNIVERSITY OF CALIFORNIA Department of Electrical Engineering and Computer Sciences Computer Science Division. P. N. Hilfinger.

UNIVERSITY OF CALIFORNIA Department of Electrical Engineering and Computer Sciences Computer Science Division. P. N. Hilfinger. UNIVERSITY OF CALIFORNIA Department of Electrical Engineering and Computer Sciences Computer Science Division CS61B Fall 2009 P. N. Hilfinger Test #1 READ THIS PAGE FIRST. Please do not discuss this exam

More information

Introductory Mobile Application Development

Introductory Mobile Application Development Notes Quick Links Introductory Mobile Application Development 152-160 Java Syntax Part 2 - Activity String Class Add section on Parse ArrayList Class methods. Book page 95. Toast Page 129 240 242 String

More information

Software Practice 1 Basic Grammar

Software Practice 1 Basic Grammar Software Practice 1 Basic Grammar Basic Syntax Data Type Loop Control Making Decision Prof. Joonwon Lee T.A. Jaehyun Song Jongseok Kim (42) T.A. Sujin Oh Junseong Lee (43) 1 2 Java Program //package details

More information

CS 101 Fall 2005 Midterm 2 Name: ID:

CS 101 Fall 2005 Midterm 2 Name:  ID: This exam is open text book but closed-notes, closed-calculator, closed-neighbor, etc. Questions are worth different amounts (in particular, the final two questions are worth substantially more than any

More information

Computer Programming, I. Laboratory Manual. Experiment #5. Strings & Text Files Input

Computer Programming, I. Laboratory Manual. Experiment #5. Strings & Text Files Input Think Twice Code Once The Islamic University of Gaza Engineering Faculty Department of Computer Engineering Fall 2017 ECOM 2005 Khaleel I. Shaheen Computer Programming, I Laboratory Manual Experiment #5

More information

More Data Types. The Char Data Type. Variable Declaration. CS200: Computer Science I. Module 14 More Data Types

More Data Types. The Char Data Type. Variable Declaration. CS200: Computer Science I. Module 14 More Data Types datatype CS200: Computer Science I Module 14 More Data Types Kevin Sahr, PhD Department of Computer Science Southern Oregon University 1 More Data Types in addition to the data types double and int we

More information

BCIS 3630 Dr. GUYNES SPRING 2018 TUESDAY SECTION [JAN version] GRADER COURSE WEBSITE

BCIS 3630 Dr. GUYNES SPRING 2018 TUESDAY SECTION [JAN version] GRADER   COURSE WEBSITE COURSE WEBSITE http://www.steveguynes.com/bcis3630/bcis3630/default.html Instructor: Dr. Guynes Office: BLB 312H Phone: (940) 565-3110 Office Hours: By Email Email: steve.guynes@unt.edu TEXTBOOK: Starting

More information

c) And last but not least, there are javadoc comments. See Weiss.

c) And last but not least, there are javadoc comments. See Weiss. CSCI 151 Spring 2010 Java Bootcamp The following notes are meant to be a quick refresher on Java. It is not meant to be a means on its own to learn Java. For that you would need a lot more detail (for

More information

CSE 1223: Introduction to Computer Programming in Java Chapter 2 Java Fundamentals

CSE 1223: Introduction to Computer Programming in Java Chapter 2 Java Fundamentals CSE 1223: Introduction to Computer Programming in Java Chapter 2 Java Fundamentals 1 Recall From Last Time: Java Program import java.util.scanner; public class EggBasketEnhanced { public static void main(string[]

More information

CS 1301 Ch 8, Part A

CS 1301 Ch 8, Part A CS 1301 Ch 8, Part A Sections Pages Review Questions Programming Exercises 8.1 8.8 264 291 1 30 2,4,6,8,10,12,14,16,18,24,28 This section of notes discusses the String class. The String Class 1. A String

More information

CS 101 Spring 2007 Midterm 2 Name: ID:

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

Exam 1 Prep. Dr. Demetrios Glinos University of Central Florida. COP3330 Object Oriented Programming

Exam 1 Prep. Dr. Demetrios Glinos University of Central Florida. COP3330 Object Oriented Programming Exam 1 Prep Dr. Demetrios Glinos University of Central Florida COP3330 Object Oriented Programming Progress Exam 1 is a Timed Webcourses Quiz You can find it from the "Assignments" link on Webcourses choose

More information

ASSIGNMENT 4 Classes and Objects

ASSIGNMENT 4 Classes and Objects ASSIGNMENT 4 Classes and Objects COMP-202A, Fall 2010, All Sections Due: Friday, November 19, 2010 (23:55) You MUST do this assignment individually and, unless otherwise specified, you MUST follow all

More information

CS Programming I: Using Objects

CS Programming I: Using Objects CS 200 - Programming I: Using Objects Marc Renault Department of Computer Sciences University of Wisconsin Madison Fall 2017 TopHat Sec 3 (PM) Join Code: 719946 TopHat Sec 4 (AM) Join Code: 891624 Binary

More information

CS163/164 Final Exam Study Session

CS163/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 information

Dining philosophers (cont)

Dining philosophers (cont) Administrivia Assignment #4 is out Due Thursday April 8, 10:00pm no late assignments will be accepted Sign up in labs this week for a demo time Office hour today will be cut short (11:30) Another faculty

More information

Intro to Strings. Lecture 7 CGS 3416 Spring February 13, Lecture 7 CGS 3416 Spring 2017 Intro to Strings February 13, / 16

Intro to Strings. Lecture 7 CGS 3416 Spring February 13, Lecture 7 CGS 3416 Spring 2017 Intro to Strings February 13, / 16 Intro to Strings Lecture 7 CGS 3416 Spring 2017 February 13, 2017 Lecture 7 CGS 3416 Spring 2017 Intro to Strings February 13, 2017 1 / 16 Strings in Java In Java, a string is an object. It is not a primitive

More information

CST242 Strings and Characters Page 1

CST242 Strings and Characters Page 1 CST242 Strings and Characters Page 1 1 2 3 4 5 6 Strings, Characters and Regular Expressions CST242 char and String Variables A char is a Java data type (a primitive numeric) that uses two bytes (16 bits)

More information

Account joeacct = new Account (100, new Account (500)); Account joeacct = new Account (100, new Account (500, null));

Account joeacct = new Account (100, new Account (500)); Account joeacct = new Account (100, new Account (500, null)); Exam information 369 students took the exam. Scores ranged from 1 to 20, with a median of 11 and an average of 11.1. There were 40 scores between 15.5 and 20, 180 between 10.5 and 15, 132 between 5.5 and

More information

Introduction to Programming Using Java (98-388)

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

Constants. Why Use Constants? main Method Arguments. CS256 Computer Science I Kevin Sahr, PhD. Lecture 25: Miscellaneous

Constants. Why Use Constants? main Method Arguments. CS256 Computer Science I Kevin Sahr, PhD. Lecture 25: Miscellaneous CS256 Computer Science I Kevin Sahr, PhD Lecture 25: Miscellaneous 1 main Method Arguments recall the method header of the main method note the argument list public static void main (String [] args) we

More information

Solution to Section #3 Portions of this handout by Eric Roberts, Mehran Sahami, Marty Stepp, Patrick Young and Jeremy Keeshin

Solution to Section #3 Portions of this handout by Eric Roberts, Mehran Sahami, Marty Stepp, Patrick Young and Jeremy Keeshin Nick Troccoli Section #3 CS 106A July 10, 2017 Solution to Section #3 Portions of this handout by Eric Roberts, Mehran Sahami, Marty Stepp, Patrick Young and Jeremy Keeshin 1. Adding commas to numeric

More information

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

More Things We Can Do With It! Overview. Circle Calculations. πr 2. π = More operators and expression types More statements More Things We Can Do With It! More operators and expression types More s 11 October 2007 Ariel Shamir 1 Overview Variables and declaration More operators and expressions String type and getting input

More information

CS 200 File Input and Output Jim Williams, PhD

CS 200 File Input and Output Jim Williams, PhD CS 200 File Input and Output Jim Williams, PhD This Week 1. WaTor Change Log 2. Monday Appts - may be interrupted. 3. Optional Lab: Create a Personal Webpage a. demonstrate to TA for same credit as other

More information

AP Computer Science A

AP Computer Science A AP Computer Science A 1st Quarter Notes Table of Contents - section links Click on the date or topic below to jump to that section Date : 9/8/2017 Aim : Java Basics Objects and Classes Data types: Primitive

More information

Variables of class Type. Week 8. Variables of class Type, Cont. A simple class:

Variables of class Type. Week 8. Variables of class Type, Cont. A simple class: Week 8 Variables of class Type - Correction! Libraries/Packages String Class, reviewed Screen Input/Output, reviewed File Input/Output Coding Style Guidelines A simple class: Variables of class Type public

More information

Software Practice 1 - Basic Grammar Basic Syntax Data Type Loop Control Making Decision

Software Practice 1 - Basic Grammar Basic Syntax Data Type Loop Control Making Decision Software Practice 1 - Basic Grammar Basic Syntax Data Type Loop Control Making Decision Prof. Hwansoo Han T.A. Minseop Jeong T.A. Wonseok Choi 1 Java Program //package details public class ClassName {

More information

CS Programming I: Using Objects

CS Programming I: Using Objects CS 200 - Programming I: Using Objects 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: 165455 Binary

More information

Chapter 2: Data and Expressions

Chapter 2: Data and Expressions Chapter 2: Data and Expressions CS 121 Department of Computer Science College of Engineering Boise State University January 15, 2015 Chapter 2: Data and Expressions CS 121 1 / 1 Chapter 2 Part 1: Data

More information

1.00 Lecture 30. Sending information to a Java program

1.00 Lecture 30. Sending information to a Java program 1.00 Lecture 30 Input/Output Introduction to Streams Reading for next time: Big Java 15.5-15.7 Sending information to a Java program So far: use a GUI limited to specific interaction with user sometimes

More information

B. Subject-specific skills B1. Problem solving skills: Supply the student with the ability to solve different problems related to the topics

B. Subject-specific skills B1. Problem solving skills: Supply the student with the ability to solve different problems related to the topics Zarqa University Faculty: Information Technology Department: Computer Science Course title: Programming LAB 1 (1501111) Instructor: Lecture s time: Semester: Office Hours: Course description: This introductory

More information

Programming Assignment Comma Separated Values Reader Page 1

Programming Assignment Comma Separated Values Reader Page 1 Programming Assignment Comma Separated Values Reader Page 1 Assignment What to Submit 1. Write a CSVReader that can read a file or URL that contains data in CSV format. CSVReader provides an Iterator for

More information

B.V. Patel Institute of BMC & IT, UTU 2014

B.V. Patel Institute of BMC & IT, UTU 2014 BCA 3 rd Semester 030010301 - Java Programming Unit-1(Java Platform and Programming Elements) Q-1 Answer the following question in short. [1 Mark each] 1. Who is known as creator of JAVA? 2. Why do we

More information

HST 952. Computing for Biomedical Scientists Lecture 8

HST 952. Computing for Biomedical Scientists Lecture 8 Harvard-MIT Division of Health Sciences and Technology HST.952: Computing for Biomedical Scientists HST 952 Computing for Biomedical Scientists Lecture 8 Outline Vectors Streams, Input, and Output in Java

More information

Fall 2017 CISC124 10/1/2017

Fall 2017 CISC124 10/1/2017 CISC124 Today First onq quiz this week write in lab. More details in last Wednesday s lecture. Repeated: The quiz availability times will change to match each lab as the week progresses. Useful Java classes:

More information

Text User Interfaces. Keyboard IO plus

Text User Interfaces. Keyboard IO plus Text User Interfaces Keyboard IO plus User Interface and Model Model: objects that solve problem at hand. User interface: interacts with user getting input from user giving output to user reporting on

More information

CS 106A Midterm Review. Rishi Bedi, adapted from slides by Kate Rydberg and Nick Troccoli Summer 2017

CS 106A Midterm Review. Rishi Bedi, adapted from slides by Kate Rydberg and Nick Troccoli Summer 2017 + CS 106A Midterm Review Rishi Bedi, adapted from slides by Kate Rydberg and Nick Troccoli Summer 2017 Details n Only the textbook is allowed n n n The Art and Science of Java Karel Course Reader You will

More information

Chapter 4 Classes in the Java Class Libraries

Chapter 4 Classes in the Java Class Libraries Programming Fundamental I ACS-1903 Chapter 4 Classes in the Java Class Libraries 1 Random Random The Random class provides a capability to generate pseudorandom values pseudorandom because the stream of

More information