AP Computer Science in Java
  • Introduction
  • Introduction to Programming in Java with Karel the Dog
    • Introduction to Programming with Karel
    • More Basic Karel
    • Java Programs and the Run Method
    • Karel Can't Turn Right
    • Methods in Karel
    • Top Down Design and Decomposition in Karel
    • Commenting Your Code
    • SuperKarel
    • For Loops
    • While Loops in Karel
    • If Statements
    • If/Else Statements
    • Control Structures Example
    • How To Indent Your Code
  • Basic Java
    • Printing in Java
    • Variables and Types
    • User Input
    • Arithmetic Expressions
    • Casting
    • Booleans
    • Logical Operators
    • Comparison Operators
    • For Loops
    • While Loops
    • If Statements
    • Loop-and-a-Half
    • Short-Circuit Evaluation
    • De Morgan's Laws
    • Strings
  • Methods
    • Java Methods
    • Methods and Parameters
    • Methods and Return Values
    • Javadoc and More Methods
    • Strings Methods
    • Strings and Characters
    • Exceptions
    • String Processing
  • Classes and Object-Oriented Programming
    • Introduction To Classes and Objects
    • Classes vs. Objects
    • Using a Class as a Client
    • Writing Classes
    • Writing Classes and Instance Methods
    • Getter and Setter Methods
    • Class Methods and Class Variables
    • Method Overloading
    • Local Variables and Scope
    • Key Terms for Classes
    • Objects vs Primitives
    • Inheritance
    • Class Design and Abstract Classes
    • Polymorphism
    • Interfaces
  • Data Structures
    • What Are Data Structures?
    • Introduction to Arrays
    • Using Arrays
    • ArrayList Methods
    • Arrays vs ArrayLists
    • 2D Arrays (Matrices or Grids)
    • Hashmaps
  • Algorithms and Recursion
    • What is an Algorithm?
    • Pseudocode
    • Linear Search
    • Binary Search
    • Selection Sort
    • Insertion Sort
    • Advanced: Recursion
    • Mergesort
Powered by GitBook
On this page

Was this helpful?

  1. Algorithms and Recursion

Pseudocode

Pseudocode is a brief explanation of code in plain English.

Writing pseudocode is a good way to map out your ideas for a program before actually writing the real code. It can help you think about the function decomposition, the top down design, and the structure of a program.

Here are some examples of pseudocode:

  • Pseudocode to put down 10 tennis balls

    repeat 10 times:
        put ball
  • Pseudocode to draw a tower on every avenue in a Karel world.

    while front is clear:
        build tower
        move
    build last tower
  • Then, you can also pseudocode the build tower part like this:

    build tower:
        turn left
        repeat 3 times:
            put ball and move
        turn around
        move down
        turn left

Writing out algorithms in pseudocode allows you to focus on the structure and important ideas of the program without worrying about syntax. Once you have a good idea of the program written in pseudocode, writing the actual program is simply a matter of turning the pseudocode into Java code.

PreviousWhat is an Algorithm?NextLinear Search

Last updated 5 years ago

Was this helpful?