Presentation is loading. Please wait.

Presentation is loading. Please wait.

Review of Previous Lesson

Similar presentations


Presentation on theme: "Review of Previous Lesson"— Presentation transcript:

1 Review of Previous Lesson
30/04/2019 Review of Previous Lesson State as many Vocabulary words and Learning Objectives that you remember from the last lesson as you can. Remember to grade yourself from

2 30/04/2019 Loops / Iteration Nested for

3 Language Features and other Testable Topics
30/04/2019 Tested in the AP CS A Exam Notes Not tested in the AP CS A Exam, but potentially relevant/useful Escape Sequences \", \\, \n inside strings \’, \t, Input System.out.print 6 Control Statements for break

4 Language Features and other Testable Topics
30/04/2019 Notes: 6. User input is not included in the AP Java subset. There are many possible ways for supplying user input: e.g., by reading from a Scanner, reading from a stream (such as a file or a URL), or from a dialog box. There are advantages and disadvantages to the various approaches. The exam does not prescribe any one approach. Instead, if reading input is necessary, it will be indicated in a way similar to the following: double x = /* call to a method that reads a floating point number */; or double x = ...; // read user input

5 A nested for Iteration Loop
30/04/2019 A nested for Iteration Loop When you have one loop inside another. Think of the outer loop as a large cog driving a smaller cog which is the inner loop. Every time the larger cog revolves once (one repetition of the outer loop), the inner cog usually revolves more than once. As a solid real life example think of the second and minute hand. The minute hand would be the outer loop. The second hand would be the inner loop.

6 A nested for Iteration Loop
30/04/2019 A nested for Iteration Loop O u t e r L o p for(initialization; condition ; increment/decrement) { Outer body statement(s); Inner body statement(s); } I n e r L o p

7 30/04/2019 Nested for Example Output: for (int outerNum = 1; outerNum <= 4; outerNum ++) { System.out.println(outerNum); for (int innerNum = 1; innerNum <= 2; innerNum ++) { System.out.println(innerNum); } ? outerNum innerNum outerNum innerNum outerNum innerNum outerNum innerNum

8 break 30/04/2019 Used to come out of a loop instantly. Whenever a break statement is encountered inside a loop, the control directly comes out of loop and the loop gets terminated for rest of the iterations. It is used along with if statement, whenever used inside loop so that the loop gets terminated for a particular condition. When a break statement is used inside a nested loop, then only the inner loop gets terminated.

9 Escape Sequences 30/04/2019 Escape Sequence Description \" Inserts a double quote character in the text at this point. \\ Inserts a backslash character in the text at this point. \n Inserts a newline in the text at this point. \' Inserts a single quote character in the text at this point. \t Inserts a tab in the text at this point. Inside “ …. “, characters preceded by a backslash (\) which has a special meaning to the compiler. AP CS subset See next slide for an example.

10 Escape Sequences Example Program
30/04/2019 Escape Sequences Example Program public class EscapeSequencesExample{ public static void main(String[] args) { System.out.print("\"The \\Crazy\nProgrammer\""); } } Output: ?

11 print & println System.out.println(“…”) System.out.print(“….”)
30/04/2019 print & println System.out.println(“…”) As you know, prints the contents inside () to the console. What you may not have realised is this is done on the current line (last cursor position – see later), it does NOT move to the next line before printing. However, what it does do is move the ‘cursor’ to the next new line AFTER printing (so that any future printing is done on the next new line). System.out.print(“….”) Prints the contents inside () on the current line (last cursor position) in the same way as println, but what it doesn’t do, is move the ‘cursor’ to the next new line after printing. Therefore, any future printing appears on the same line as the last print. See next slide for an example.

12 println Vs print Example Program
30/04/2019 println Vs print Example Program public class PrintlnVsPrintExample { public static void main(String[] args) { System.out.println("test"); System.out.print("JA"); System.out.print("VA"); System.out.println("test2"); } } Output: ?

13 30/04/2019 Write your own programs: Write your own programs from “scratch”. Of course you should use previous programs for reference, but write your code from “scratch” (do not copy and paste).

14 Addition Table Specification: 30/04/2019
Write a program to display the sum of row and column numbers.

15 4/30/2019 Grade yourself Grade yourself on the vocabulary and learning objectives of the presentation.


Download ppt "Review of Previous Lesson"

Similar presentations


Ads by Google