Lecture 7 (Sherriff) - Scanner and println

Lecture Date: Wednesday, January 28

Now that we’ve gone through the break-neck pace of seeing a ton of stuff with Turtle, we’ll slow down and go through all the component parts that we used. We’ll also review how the submission system works. Yeah Homework!

It would be helpful if you have at least scanned Chapter 2 - we’ll be covering a decent amount of that chapter today and Monday.

Main topics for today:

  • Review the parts of a program (code blocks, public static void main, variables)
  • Review how output works with System.out.println
  • Do some basic math and output it to the screen
  • Introduce how to get user input using Scanner
  • How to work with the String class
  • How to manipulate a String

APIs

An API is the list of methods that are provided with a programming language or programming tool.

For example, if s, t, and u are Strings then you can do the following:

CodeAction
s.length()returns the number of characters in s
s.replace(t, u)returns a new String that is like s except that every occurrence of t has been replaced with u instead
s.charAt(0)returns the first character in s
s.charAt(3)returns the fourth character in s
Integer.parseInt(s)returns the number that s represents (e.g., if s were "134" it would return 134

Code from today: BasicProgramming.java