Website: Consultation hours: By appointment

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

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

Basics of Java Programming Input and the Scanner class

Sample CSE8A midterm Multiple Choice (circle one)

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

Building Java Programs

Building Java Programs

Introduction to Programming

AP Computer Science Static Methods, Strings, User Input

Programming Languages CIS 443

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

Tutorial 0A Programming on the command line

CS170 Lab 11 Abstract Data Types & Objects

CSE 8B Midterm Fall 2015

Comp 248 Introduction to Programming

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

Object-Oriented Programming in Java

Vim, Emacs, and JUnit Testing. Audience: Students in CS 331 Written by: Kathleen Lockhart, CS Tutor

Using Files as Input/Output in Java 5.0 Applications

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

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

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

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

Chapter 3. Input and output. 3.1 The System class

Install Java Development Kit (JDK) 1.8

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

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

Building Java Programs

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

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

Topic 11 Scanner object, conditional execution

Visit us at

Data Structures Lecture 1

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

Chapter 2: Elements of Java

1001ICT Introduction To Programming Lecture Notes

Introduction to Java

6.1. Example: A Tip Calculator 6-1

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

Java CPD (I) Frans Coenen Department of Computer Science

Linux Overview. Local facilities. Linux commands. The vi (gvim) editor

CS 106 Introduction to Computer Science I

Introduction to Computer Programming, Spring Term 2014 Practice Assignment 3 Discussion

AP Computer Science Java Subset

Course Intro Instructor Intro Java Intro, Continued

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

Introduction to Java. CS 3: Computer Programming in Java

First Java Programs. V. Paúl Pauca. CSC 111D Fall, Department of Computer Science Wake Forest University. Introduction to Computer Science

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

Homework/Program #5 Solutions

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

MIDTERM 1 REVIEW WRITING CODE POSSIBLE SOLUTION

JAVA ARRAY EXAMPLE PDF

AP Computer Science File Input with Scanner

WA2099 Introduction to Java using RAD 8.0 EVALUATION ONLY. Student Labs. Web Age Solutions Inc.

CS 106 Introduction to Computer Science I

Running Hadoop on Windows CCNP Server

How to Install Java onto your system

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

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

Topics. Parts of a Java Program. Topics (2) CS 146. Introduction To Computers And Java Chapter Objectives To understand:

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

Agenda. Using HPC Wales 2

Some Scanner Class Methods

Week 1: Review of Java Programming Basics

Chapter 2 Basics of Scanning and Conventional Programming in Java

Handout 3 cs180 - Programming Fundamentals Spring 15 Page 1 of 6. Handout 3. Strings and String Class. Input/Output with JOptionPane.

Section 6 Spring 2013

Topics. Introduction. Java History CS 146. Introduction to Programming and Algorithms Module 1. Module Objectives

Reading Input From A File

Introduction to Mac OS X

LAB 1. Familiarization of Rational Rose Environment And UML for small Java Application Development

PA2: Word Cloud (100 Points)

Chapter 2 Introduction to Java programming

Chapter 2 Elementary Programming

qwertyuiopasdfghjklzxcvbnmqwerty uiopasdfghjklzxcvbnmqwertyuiopasd fghjklzxcvbnmqwertyuiopasdfghjklzx cvbnmqwertyuiopasdfghjklzxcvbnmq

Command Line - Part 1

Basic C Shell. helpdesk@stat.rice.edu. 11th August 2003

Lab 5: Bank Account. Defining objects & classes

Simple Java I/O. Streams

How to use the Eclipse IDE for Java Application Development

You are to simulate the process by making a record of the balls chosen, in the sequence in which they are chosen. Typical output for a run would be:

Notepad++ The COMPSCI 101 Text Editor for Windows. What is a text editor? Install Python 3

Java Software Development Kit (JDK 5.0 Update 14) Installation Step by Step Instructions

Introduction to programming

Lab 1: Introduction to C, ASCII ART and the Linux Command Line Environment

Interactive Programs and Graphics in Java

Files and input/output streams

Introduction to Object-Oriented Programming

2 Getting Started with jgrasp 2.0

Dalhousie University CSCI 2132 Software Development Winter 2015 Lab 7, March 11

Java Crash Course Part I

B.Sc (Honours) - Software Development

Manual For Using the NetBeans IDE

LAB4 Making Classes and Objects

Assignment 4 Solutions

CPSC 226 Lab Nine Fall 2015

Continuous Integration Part 2

Lecture 5: Java Fundamentals III

Programmierpraktikum

Transcription:

Lab TA: Nicholas CS Year 3 Email: nicholaslum@u.nus.edu Website: http://comp.nus.edu.sg/~lum76 Consultation hours: By appointment 2

Guidance for take-home labs Issues with vim Issues with sunfire/unix Feedback for lab submissions Consultations 3

Attempt take-home labs before Thursday Ask for help early; don t wait until last minute Code on vim/unix to build confidence Sleep early before Sit-In Lab! 4

Unix Environment Input Output 5

Change Directory (cd) cd [directory name] Use [Tab] button for auto-completion List Content (ls) ls (list current directory) ls all (include hidden files/folders) Remove Directory Entries (rm) rm [file/folder name] Java Compile (javac) javac *.java (shortcut to compile all java files) 6

Edit File in VIM (vim) vim [file name] Running Java Program (java) java [program name without extension] java [class name] < [input file] > [output file] (input/output redirection) Checking for Difference (diff) diff [file name] [file name] Difference in a single space or an extra line will be noted Manual (man) man [command name] When you are not sure what the command does, or what parameter it expects 7

Command Mode: (to get into command mode, press ESC key) 1. dd or :d Delete the current line 2. :q! Exit without saving changes 3. :wq or ZZ Save and Exit 4. /[pattern] Search for the pattern n Search next in the same direction N Search next in the opposite direction More commands (copy, cut, paste, end of line, etc): http://www.keyxl.com/aaa8263/290/vim-keyboard-shortcuts.htm 8

Unix Environment Input Output 9

Scanner Class Initialization: Scanner sc = new Scanner (System.in); hasnext() and variants Check if there exists another input next() and variants Get the next input Variants: Int, Line, Double example: hasnextint() and nextline() There is NO nextchar() and hasnextchar() variant Type of Input: (from Lab 0 Problem 1) o Type 1: Number of Operations is specified o Type 2: Read until Terminating Special Character o Type 3: Read until End of File 10

public static void main(string[] args) { // Code Section Omitted // Other Initialization Scanner sc = new Scanner(System.in); int numops = sc.nextint(); for (int i=0; i<numops; i++) { // Read Other Inputs // Code Section Omitted 11

Steps: 1. Initialize the Scanner Class Scanner sc = new Scanner(System.in); 2. Read the First Input String tempinput = sc.next(); 3. Loop until Terminating Special Character encountered while (!tempinput.equals(terminating_char)) { // Read Other Input (if exist) // Step 4 Here 4. Read into tempinput again tempinput = sc.next(); 12

public static void main(string[] args) { // Code Section Omitted // Other Initialization Scanner sc = new Scanner(System.in); String tempinput = sc.next(); while (!tempinput.equals(terminating_char)) { // Read Other Input tempinput = sc.next(); // Code Section Omitted 13

Steps: 1. Initialize the Scanner Class Scanner sc = new Scanner(System.in); 2. Loop until End of File while (sc.hasnext()) { // Read Other Input 14

public static void main(string[] args) { // Code Section Omitted // Other Initialization Scanner sc = new Scanner(System.in); while (sc.hasnext()) { // Read Other Inputs // Code Section Omitted 15

Combines two or more different input types into a single program e.g.: Type 3 Input on the Outside, Type 1 Input on the Inside. public static void main(string[] args) { // Code Section Omitted // Other Initialization Scanner sc = new Scanner (System.in); while (sc.hasnext()) { int numops = sc.nextint(); for (int i=0; i<numops; i++) { // Read Other Inputs // Code Section Omitted 16

Unix Environment Input Output 17

With Extra Line at the End System.out.println("Output String Here"); System.out.print("Output String Here\n"); Without Extra Line at the End System.out.print("Output String Here"); 18

One per Line, Terminate with End Line for (int i=0; i<numoutput; i++) { System.out.println(outputString); One per Line, Terminate without End Line System.out.print(outputString); for (int i=1; i<numoutput; i++) { System.out.println(); System.out.print(outputString); 19

Matrix Type, End Space for (int i=0; i<numline; i++) { for (int j=0; j<numout; j++) { System.out.print (output + " "); System.out.println(); Matrix Type, End Not Space for (int i=0; i<numline; i++) { System.out.print (output); for (int j=1; j<numout; j++) { System.out.print (" " + output); System.out.println(); 20

Questions?