June 1st algorithm-while loop Flashcards
algorithm
A well-ordered collection of unambiguous & effectively computable operations that, when executed produces a result & halts in a finite amount of time.
Boolean expression
- a data type with two possible values: true and false.
For example: the expression (x = 1) is a Boolean expression because it is true if x is 1, and it is false if x has any other value. Similarly, both (a can’t = b) and (c > 5.23) are Boolean expressions.
class
- a programmer-defined data type (defines a class) | (Big Java Pg. 33) describes a set of objects with the same behavior. Describes the behavior of these
objects. - System.out
- “Hello, World!”
Each of these objects belongs to a different class.
The System.out object belongs to
the PrintStream class. The “Hello, World!” object belongs to the String class
compiler
- a program that translates code in a high-level
language (such as Java) to machine instructions
(such as bytecode for the Java virtual machine). - The Java compiler translates source code into class files that contain instructions for the Java virtual machine. In a high-level language, you specify the actions that your program should carry out.
if-else
- Conditional statements are the “question-asking” operations of an algorithm. allow an algorithm to ask a yes/no question and select the next operation to perform on the basis of the answer to that question.
- There are a number of ways to phrase a question, but the most common conditional statement is the if/then/else statement, which has the following format:
If “a true/false condition” is true then
first set of algorithmic operations
Else (or otherwise)
second set of algorithmic operations
The meaning of this statement is as follows:
1. Evaluate the true/false condition on the first line to determine whether it
is true or false.
2. If the condition is true, then do the first set of algorithmic operations and
skip the second set entirely.
3. If the condition is false, then skip the first set of operations and do the second set.
4. Once the appropriate set of operations has been completed, continue executing
the algorithm with the operation that follows the if/then/else instruction
Basically, the if/then/else statement allows you to select exactly one of
two alternatives—either/or, this or that.
while loop
- a looping statement to express the idea of iteration (repetition of a process or utterance.
- This instruction initially evaluates the “true/false condition”—called the
continuation condition—to determine if it is true or false. If the condition is
true, all operations from Step i to Step j, inclusive, are executed. This block of
operations is called the loop body. (Operations within the loop body should
be indented so that it is clear to the reader of the algorithm which operations
belong inside the loop.) When the entire loop body has finished executing, the
algorithm again evaluates the continuation condition. If it is still true, then
the algorithm executes the entire loop body, statements i through j, again.
This looping process continues until the continuation condition evaluates to
false, at which point execution of the loop body terminates and the algorithm
proceeds to the statement immediately following the loop—Step j + 1 in the
above pseudocode. If for some reason the continuation condition never becomes
false, then we have violated one of the fundamental properties of an algorithm,
and we have the error, first mentioned in Chapter 1, called an infinite loop
for loop
- the for loop neatly groups the initialization, condition, and update expressions together. these expressions are not executes together it is used when a value runs from a starting point to an ending point with a constant increment or decrement.
Example:
for (int i = 5; i <= 10; i++) // initialization; condition; update
{
sum = sum + 1; //statements
}
computer science
- the study of algorithms, including
1. Their formal and mathematical properties
2. Their hardware realizations
3. Their linguistic realizations
4. Their applications
data type
- its data type, which is integer. (The data type information comes from the integer) how to represent data types such as unsigned and signed integers, floating-point values, and characters in binary. When writing in machine language, the programmer must do these conversions.
declare
- When declaring a variable, you usually specify an initial value. The following statement declares a variable named width:
int width = 20;
- declare is not to declare “value” to a variable; it’s to declare the type of the variable.
pseudocode
- Most computer scientists use a notation called pseudocode to design and represent algorithms. This is a set of English-language constructs designed to more or less resemble statements in a programming language but that do not actually run on a computer.
- Pseudocode represents a compromise between the two extremes of natural and formal languages. It is simple, highly readable, and has virtually no grammatical rules. (In fact, pseudocode is sometimes jokingly referred to as “a programming language without the details.”)
initialize
- The process of assigning the value of the variable is called initialization of state of an object. In other words, Initialization is the process of storing data into an object.
- An important difference between instance variables and local variables is initialization. You must initialize all local variables.
- is the assignment of a value to a variable at the time of declaration.
(assignment is simply the storing of a value to a variable.