Visit us at www.apluscompsci.com

Similar documents
JAVA.UTIL.SCANNER CLASS

Object-Oriented Programming in Java

CS 106 Introduction to Computer Science I

Basics of Java Programming Input and the Scanner class

Decision-making Computer Science Lesson to Prepare for UIL Computer Science Contest

CSE 1223: Introduction to Computer Programming in Java Chapter 7 File I/O

Introduction to Java

Scanner. It takes input and splits it into a sequence of tokens. A token is a group of characters which form some unit.

Chapter 2: Elements of Java

Chulalongkorn University International School of Engineering Department of Computer Engineering Computer Programming Lab.

Topic 11 Scanner object, conditional execution

Comp 248 Introduction to Programming

Building Java Programs

13 File Output and Input

File class in Java. Scanner reminder. Files 10/19/2012. File Input and Output (Savitch, Chapter 10)

Principles of Software Construction: Objects, Design, and Concurrency. Design Case Study: Stream I/O Some answers. Charlie Garrod Jonathan Aldrich

Using Files as Input/Output in Java 5.0 Applications

Reading Input From A File

Building Java Programs

Carron Shankland. Content. String manipula3on in Java The use of files in Java The use of the command line arguments References:

Course Intro Instructor Intro Java Intro, Continued

AP Computer Science File Input with Scanner

Building Java Programs

Scanner sc = new Scanner(System.in); // scanner for the keyboard. Scanner sc = new Scanner(System.in); // scanner for the keyboard

Chapter 2. println Versus print. Formatting Output withprintf. System.out.println for console output. console output. Console Input and Output

Handout 1. Introduction to Java programming language. Java primitive types and operations. Reading keyboard Input using class Scanner.

6.1. Example: A Tip Calculator 6-1

Some Scanner Class Methods

JDK 1.5 Updates for Introduction to Java Programming with SUN ONE Studio 4

D06 PROGRAMMING with JAVA

JAVA ARRAY EXAMPLE PDF

Simple Java I/O. Streams

Introduction to Java. CS 3: Computer Programming in Java

Preet raj Core Java and Databases CS4PR. Time Allotted: 3 Hours. Final Exam: Total Possible Points 75

READING DATA FROM KEYBOARD USING DATAINPUTSTREAM, BUFFEREDREADER AND SCANNER

Install Java Development Kit (JDK) 1.8

Building Java Programs

Cohort: BCA/07B/PT - BCA/06/PT - BCNS/06/FT - BCNS/05/FT - BIS/06/FT - BIS/05/FT - BSE/05/FT - BSE/04/PT-BSE/06/FT

Line-based file processing

CSE 8B Midterm Fall 2015

AP Computer Science Static Methods, Strings, User Input

Programming Languages CIS 443

qwertyuiopasdfghjklzxcvbnmqwerty uiopasdfghjklzxcvbnmqwertyuiopasd fghjklzxcvbnmqwertyuiopasdfghjklzx cvbnmqwertyuiopasdfghjklzxcvbnmq

Computer Programming I

Event-Driven Programming

java.util.scanner Here are some of the many features of Scanner objects. Some Features of java.util.scanner

System.out.println("\nEnter Product Number 1-5 (0 to stop and view summary) :

CS 121 Intro to Programming:Java - Lecture 11 Announcements

Chapter 10. A stream is an object that enables the flow of data between a program and some I/O device or file. File I/O

Files and input/output streams

IMDB Data Set Topics: Parsing Input using Scanner class. Atul Prakash

Sample CSE8A midterm Multiple Choice (circle one)

Data Structures Lecture 1

Programming in Java. What is in This Chapter? Chapter 1

AP Computer Science Java Mr. Clausen Program 9A, 9B

Chapter 3. Input and output. 3.1 The System class

More on Objects and Classes

Introduction to Programming

Translating to Java. Translation. Input. Many Level Translations. read, get, input, ask, request. Requirements Design Algorithm Java Machine Language

Chapter 2 Elementary Programming

CS 141: Introduction to (Java) Programming: Exam 1 Jenny Orr Willamette University Fall 2013

The following program is aiming to extract from a simple text file an analysis of the content such as:

Question1-part2 What undesirable consequences might there be in having too long a DNS cache entry lifetime?

Chapter 20 Streams and Binary Input/Output. Big Java Early Objects by Cay Horstmann Copyright 2014 by John Wiley & Sons. All rights reserved.

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

Software Development in Java

Interactive Programs and Graphics in Java

Programming Fundamentals I CS 110, Central Washington University. November 2015

MIDTERM 1 REVIEW WRITING CODE POSSIBLE SOLUTION

Chapter 8. Living with Java. 8.1 Standard Output

Question R11.3. R11.3 How do you open a file whose name contains a backslash, like c:\temp\output.dat?

Part I. Multiple Choice Questions (2 points each):

Quick Introduction to Java

IRA EXAMPLES. This topic has two examples showing the calculation of the future value an IRA (Individual Retirement Account).

Week 1: Review of Java Programming Basics

CS 112/ Section 02 Hilal Ünal Aslıhan Ekim Merve Özkılınç Notes of March 11, 2008 and March 13, 2008: Pig Latin: add adday. main.

Classes and Objects in Java Constructors. In creating objects of the type Fraction, we have used statements similar to the following:

1) Which of the following is a constant, according to Java naming conventions? a. PI b. Test c. x d. radius

Assignment 4 Solutions

Introduction to Java Applications Pearson Education, Inc. All rights reserved.

CompSci 125 Lecture 08. Chapter 5: Conditional Statements Chapter 4: return Statement

COSC Introduction to Computer Science I Section A, Summer Question Out of Mark A Total 16. B-1 7 B-2 4 B-3 4 B-4 4 B Total 19

- User input includes typing on the keyboard, clicking of a mouse, tapping or swiping a touch screen device, etc.

Using Two-Dimensional Arrays

Arrays. Atul Prakash Readings: Chapter 10, Downey Sun s Java tutorial on Arrays:

Lösningsförslag till tentamen

Introduction to Java Lecture Notes. Ryan Dougherty

Program Logic to Java GEEN163

MULTIPLE CHOICE. Choose the one alternative that best completes the statement or answers the question.

Explain the relationship between a class and an object. Which is general and which is specific?

CS1020 Data Structures and Algorithms I Lecture Note #1. Introduction to Java

Creating a Simple, Multithreaded Chat System with Java

Programming and Data Structures with Java and JUnit. Rick Mercer

Masters programmes in Computer Science and Information Systems. Object-Oriented Design and Programming. Sample module entry test xxth December 2013

Third AP Edition. Object-Oriented Programming and Data Structures. Maria Litvin. Gary Litvin. Phillips Academy, Andover, Massachusetts

Lab 5: Bank Account. Defining objects & classes

Assignment No.3. /*-- Program for addition of two numbers using C++ --*/

Interactive Applications (CLI) and Math

JAVA for Beginners. 2 nd Edition. Riccardo Flask

COSC 111: Computer Programming I. Dr. Bowen Hui University of Bri>sh Columbia Okanagan

Transcription:

Visit us at www.apluscompsci.com Full Curriculum Solutions M/C Review Question Banks Live Programming Problems Tons of great content! www.facebook.com/apluscomputerscience

Scanner kb = new Scanner(System.in); int val = kb.nextint();

A data file is a sequential list of data. nums.dat 123 567 345 128

Output file stream Input file stream The program sends data to the file. Java Program The program gets data from the file. The program is always in control when working with files.

Scanner file = new Scanner(new File("nums2.dat")); int val = file.nextint(); nums2.dat 567 345 25

Scanner is a class in Java that can be used to read in data from the keyboard or from a data file. Scanner can also be used to chop up Strings.

Scanner kb = new Scanner(System.in); Scanner chopper = new Scanner("a b c d e"); Scanner file = new Scanner(new File("pr21.dat"));

Scanner keyboard = new Scanner(System.in); object / reference constructor parameter Scanner file = new Scanner(new File("prxx.dat"));

Scanner frequently used methods Name nextint() nextdouble() next() nextline() hasnextint() hasnextdouble() hasnext() Use returns the next int value returns the next double value returns the next one word String returns the next multi word String checks to see if there are more ints checks to see if there are more doubles checks to see if there are more Strings import java.util.scanner;

for.dat 6 23 11 6634 123 532 123 # of data sets (6)

Scanner file = new Scanner(new File("for.dat")); int cnt = file.nextint(); for(int i=0; i<cnt; i++) { int num = file.nextint(); out.println(num); }

Scanner file = new Scanner(new File("for.dat")); int cnt = file.nextint(); for(int i=0; i<cnt; i++) { int num = file.nextint(); out.println(num); } for.dat 3 11 5 67 OUTPUT 11 5 67

Visit us at www.apluscompsci.com Full Curriculum Solutions M/C Review Question Banks Live Programming Problems Tons of great content! www.facebook.com/apluscomputerscience

while.dat 34 23 11 6634 123 532 123 531 # of data sets (?)

Scanner file = new Scanner(new File("while.dat")); while(file.hasnextint()) { int num = file.nextint(); out.println(num); }

Scanner file = new Scanner(new File("while.dat")); while(file.hasnextint()) { int num = file.nextint(); out.println(num); } while.dat 11 5 67 OUTPUT 11 5 67

forlines.dat 3 I went to the store. The big dog ran. How are you doing? # of data sets (3)

Scanner file; file = new Scanner(new File("forlines.dat")); int cnt = file.nextint(); file.nextline(); //clear out whitespace for(int i=0; i<cnt; i++) { String sentence = file.nextline(); out.println(sentence); }

whilelines.dat I went to the store. The big dog ran. How are you doing? # of data sets (?)

Scanner file; file = new Scanner( new File("whilelines.dat")); while(file.hasnext()) { out.println(file.nextline()); }

Visit us at www.apluscompsci.com Full Curriculum Solutions M/C Review Question Banks Live Programming Problems Tons of great content! www.facebook.com/apluscomputerscience

PrintWriter fileout = new PrintWriter( new FileWriter("out.dat"));

PrintWriter fileout = new PrintWriter( new FileWriter("out.dat")); for(int i=0; i<10; i++) { fileout.println(i); } fileout.close();

Every file you open you must also close. file.close(); kb.close();

Visit us at www.apluscompsci.com Full Curriculum Solutions M/C Review Question Banks Live Programming Problems Tons of great content! www.facebook.com/apluscomputerscience