Presentation is loading. Please wait.

Presentation is loading. Please wait.

Introduction to Programming Overview of Week 2 25 January 2013 1 Ping Brennan

Similar presentations


Presentation on theme: "Introduction to Programming Overview of Week 2 25 January 2013 1 Ping Brennan"— Presentation transcript:

1 Introduction to Programming Overview of Week 2 25 January 2013 1 Ping Brennan (y.p.brennan@dcs.bbk.ac.uk)

2 Review of Week 2 topics Declaring variables –int cansPerPack = 6; –String str = "Harry Potter"; Number types –int, double 2

3 Review of Week 2 topics (2) Keyboard input: nextInt() – reads an integer value nextDouble() – reads a floating-point value nextLine() – reads a line of text string up to but not including the newline character. next() – reads the next whitespace-delimited string, that is, only one word is read. String operations: –substring(startPosition, endPosition(optional)) e.g. str.substring(0, 5); str.substring(6); –length(), + symbol for string concatenation. 3

4 Keyboard input using the Scanner Class import java.util.Scanner; /* The package java.util contains the class java.util.Scanner. A package is a collection of classes with a related purpose. The import statement is typed in as the first line of the program before the definition of the class which uses java.util.Scanner. */ Scanner in = new Scanner(System.in); /* new is used to create a new object of type Scanner. The name of the new object is called in to read keyboard input. Note that new is a reserved word, and Scanner on the left acts like a type declaration. System. in identifies the keyboard as the source of input. */ 4

5 End of Overview 5


Download ppt "Introduction to Programming Overview of Week 2 25 January 2013 1 Ping Brennan"

Similar presentations


Ads by Google