Chapter 1 Flashcards
What is a program?
consists of instructions executing one at time. Basic instruction types include Input, Process, output.
Define input
A program gets data, perhaps from a file, keyboard, touchscreen, network.
Define a Process
A program performs computations on data such as adding two values like x+y
Define Output
A program puts that data somewhere like a file, screen, network, etc…
Define computational thinking
creating a sequence of instructions to solve a problem
Define an algorithm
Sequence of instructions that solves a problem
Each statement typically appears alone on a line and ends with a _?
semicolon
int stands for?
Integer. example: int wage. The statement int wage; creates a variable named wage that is used to hold the variable. The variable wage can be assigned with a different value later in the program, so because the value held can vary, the item is called a variable. Program variables are different from variables in algebra.
Program execution begins at main() and executes statements surrounded by which symbols?
{ }
Program execution begins at main() and executes statements surrounded by which symbols?
Define Scanner
a text parser that can get numbers, words, or phrases from an input source such as the keyboard.
What is the statement to create a scanner onject
scnr = new Scanner(System.in);. System.in corresponds to keyboard input. Then, given Scanner object scnr, the following statement gets an input value and assigns x with that value: x = scnr.nextInt()
Define String Literal
Text in double quotes “ “ Outputting text is achieved via: System.out.print(“desired text”);
How do you out out a blank line?
System.out.println().
Define comment
Text ap rogrammer adds to code, to be read by humans to better understand the code but ignored by the compiler. Two common kinds of comments exist:
A single-line comment starts with // and includes all the following text on that line. Single-line comments commonly appear after a statement on the same line.
A multi-line comment starts with /* and ends with /, where all text between / and */ is part of the comment. A multi-line comment is also known as a block comment.
Define a single-line comment
A single-line comment starts with // and includes all the following text on that line. Single-line comments commonly appear after a statement on the same line.
Example
/*
This program calculates the amount of pasta to cook, given the
number of people eating.
Author: Andrea Giada
Date: May 30, 2017
*/
Define a multi-line comment
starts with /* and ends with /, where all text between / and */ is part of the comment. A multi-line comment is also known as a block comment. Example
int totalOuncesPasta; // Total ounces of pasta to serve numPeople
Define Whitespace
Whitespace refers to blank spaces (space and tab characters) between items within a statement and blank lines between statements (called newlines). A compiler ignores most whitespace.
Describe Good practice is to deliberately and consistently use whitespace to make a program more readable. Programmers usually follow conventions defined by their company, team, instructor, etc., such as:
Use blank lines to separate conceptually distinct statements.
Indent lines the same amount.
Align items to reduce visual clutter.
Use a single space before and after any operators like =, +, *, or / to make statements more readable.
Define Syntax error
is to violate a programming language’s rules on how symbols can be combined to create a program. An example is forgetting to end a statement with a semicolon
Find the syntax errors. Assume variable numDogs has been declared.
1)
System.out.print(numDogs).
Error Statements end with a semicolon, not period.
Find the syntax errors. Assume variable numDogs has been declared
System.out.print(“Dogs: “ numDogs);
Error
Missing + before numDogs
Find the syntax errors. Assume variable numDogs has been declared
system.out.print(“Everyone wins.”);
Error
Should be an uppercase S in System.