[an error occurred while processing this directive]
[an error occurred while processing this directive]
University of Washington, AP/CS A
Lab 2: Expressions
Except where otherwise noted, the contents of this document are
Copyright 2013 Stuart Reges and Marty Stepp.
lab document created by Marty Stepp, Stuart Reges and Whitaker Brand
Today's lab
Goals for this lab:
-
write and evaluate expressions to compute numeric
values
-
write and evaluate expressions that involve string
concatenation with numeric values
-
write and evaluate boolean expressions
-
note that a yellow response indicates that you have the correct response
but not in the correct format (e.g., entering 17 for a double value
instead of 17.0 or not including quotation marks around a string)
- Where you see this icon, you can click it to check the problem in
Practice-It!
Expressions
Recall that Java has expressions to represent math and other computations. Expressions may use operators, which are evaluated according to rules of precedence. Every expression produces a value of a given type.
Type |
Description |
Expression Example |
Result |
int |
integers (up to 231 - 1) |
3 + 4 * 5 |
23 |
double |
real numbers (up to 10308) |
3.0 / 2.0 + 4.1 |
5.6 |
String |
text characters |
"hi" + (1 + 1) + "u" |
"hi2u" |
[an error occurred while processing this directive]
[an error occurred while processing this directive]
[an error occurred while processing this directive]
[an error occurred while processing this directive]
[an error occurred while processing this directive]
[an error occurred while processing this directive]
[an error occurred while processing this directive]