Java Chapter 2

¡Supera tus tareas y exámenes ahora con Quizwiz!

An identifier must start with a letter, an underscore (_), or _. It cannot start with _.

$, a digit

Remainder is very useful in programming. For example, an even number _ is always 0 and an odd number _ is always 1. Thus, you can use this property to determine whether a number is even or odd.

% 2

If today is Saturday, it will be Saturday again in 7 days. Suppose you and your friends are going to meet in 10 days. What day is in 10 days? You can find that the day is Tuesday using the following expression:

(6 + 10) % 7 is 2 (Day 2 in a week is Tuesday, Day 0 is Sunday; Day 6 in a week is Saturday; a week has 7 days)

Integer Literals: The statement byte b = 128, for example, will cause a compile error, because the range for a byte value is from _.

-128 to 127

-26 % -8 yields

-2

Floating-point literals are written with a decimal point. By default, a floating-point literal is treated as a __ type value, not a _ type value.

double, float

An _ represents a computation involving values, variables, and operators that, taking them together, evaluates to a value

expression

You can make a number a float by appending the letter _, and you can make a number a double by appending the letter _.

f/F, d/D

The word _ is a Java keyword for declaring a constant.

final

syntax for declaring a constant

final datatype CONSTANTNAME = value;

Declare a constant for pi 3.14

final double PI = 3.14; (remember capitals)

Java uses the 32-bit IEEE 754 for the _ type and the 64-bit IEEE 754 for the _ type.

float, double

Real numbers (i.e., numbers with a decimal point) are represented using a method known as _ in computers.

floating-point

To perform a float-point division, one of the operands must be a _. For example, 5.0 / 2 yields 2.5.

floating-point number

So, the real numbers are also called _

floating-point numbers

Java provides simple data types for representing integers, real numbers, characters, and Boolean types. These types are known as primitive data types or _.

fundamental types

An _ is a sequence of characters that consists of letters, digits, underscores (_), and dollar signs ($).

identifier

Here, a and b are _ for the _ method and the numbers 2 and 3 are actual values used to invoke the method. For example, System.out.println(Math.pow(2, 3)); // Displays _

parameters, pow, 8.0

Java provides simple data types for representing integers, real numbers, characters, and Boolean types. These types are known as _ or fundamental types.

primitive data types

_ moves to the beginning of the next line after displaying the string, but _ does not advance to the next line when completed.

println, print

System.out.print("Enter a number for radius: ") is known as a _

prompt

When both operands of a division are integers, the result of the division is the _ and the fractional part is truncated. For example, 5 / 2 yields 2, not 2.5.

quotient, 2

The % operator, known as _ or _ operator

remainder, modulo

An identifier cannot be a _

reserved word

The _ word _ indicates that radius and area are floating-point values stored in the computer.

reserved, double

Every variable has a _; the part of the program where the variable can be referenced.

scope

Line 9 prompts the user to enter three numbers. The numbers are read in lines 10-12. You may enter three numbers _, then press the Enter key, or enter each number followed by a press of the Enter key, as shown in the sample runs of this program.

separated by spaces

There are two types of import statements: _ import and _ import

specific, wildcard

The plus sign (+) has two meanings: one for addition and the other for concatenating (combining) strings. The plus sign for concatenating is called a _.

string concatenation operator

A float value has _ number of significant digits and a double value has _ number of significant digits.

7-8, 15-17

By convention, the _ character should be used only in mechanically generated source code

$

-7 % 3 yields

-1

-12 % 4 yields

0

12 % 4 yields

0

By default, an integer literal is a decimal integer number. To denote a binary integer literal, use a leading _.

0B (/ob (zero B))

A special syntax is used to write scientific notation numbers. For example, 1.23456 * 10**2 is written as 1.23456E2 or 1.23456E+2 and 1.23456 * 10**-2 as _. E (or e) represents an exponent and can be in either lowercase or uppercase.

1.23456E-2

A special syntax is used to write scientific notation numbers. For example, 1.23456 * 10**2 is written as _ or 1.23456E+2 and 1.23456 * 10-2 as 1.23456E-2. E (or e) represents an exponent and can be in either lowercase or uppercase.

1.23456E2

20 % -13 yields

7

$2, ComputeArea, area, radius, and print, 2A and d+4. Which would be detected by the compiler as illegal identifiers?

2A, d+4

3 % 7 yields

3

Java uses the _-bit for the float type and _-bit for the double type.

32, 64

constants, naming convention

CAPITALIZED

class name, naming convention

Capitalized

IEEE 754 is a standard approved by the _ for representing floating-point numbers on computers.

Institute of Electrical and Electronics Engineers

An integer literal is assumed to be of the int type, whose value is between -231 (-2147483648) and 231 - 1 (2147483647). To denote an integer literal of the long type, append the letter _ to it.

L/l

The _ method can be used to compute a**b. The pow method is defined in the __ in the Java API.

Math.pow(a, b), Math class

The syntax __ declares that input is a variable whose type is Scanner.

Scanner input

Console input is not directly supported in Java, but you can use the Scanner class to create an object to read input from System.in, as follows:

Scanner input = new Scanner(System.in);

Floating-point literals can be written in scientific notation in the form of _

a * 10**b

Floating-point literals are written with __.

a decimal point

The specific import specifies _ in the import statement.

a single class

In Java, an assignment statement is essentially an expression that evaluates to the value to be assigned to the variable on the left side of the assignment operator. For this reason, an assignment statement is also known as an _.

assignment expression

In Java, the equal sign =() is used as the __.

assignment operator

After a variable is declared, you can assign a value to it by using an __.

assignment statement

In mathematics, x = 2 * x + 1 denotes an equation. However, in Java, x = 2 * x + 1 is an __ that evaluates the expression 2 * x + 1 and _ the result to x.

assignment statement, assigns

Scanner input = new Scanner(System.in); System.out.print("Enter a byte value: "); ????

byte byteValue = input.nextByte();

byte, short, int, long, float, and double. Which of these data types requires the least & most amount of memory?

byte, double

Java uses four types for integers:

byte, int, long, short

An identifier _ be of any length.

can

Identifiers are the names that identify the elements such as _, and variables in a program.

classes, methods

The syntax for declaring a variable is __

datatype variableName;

By default, an integer literal is a __

decimal integer number

area, Area, and AREA are all _.

different identifiers (Java is case sensitive)

The operand on the left is the _and the operand on the right is the _. Therefore, 7 % 3 yields 1

dividend, divisor

Declare interestRate to be a double variable

double interestRate;

Java uses two types for floating-point numbers: float and double. The double type is twice as big as float, so the double is known as _ and float as single precision. Normally, you should use the _ type, because it is more accurate.

double precision, double

System.out.print("Enter a number for radius: "); Now enter the code to except user Radius entry:

double radius = input.nextDouble();

This statement reads a number from the keyboard and assigns the number to radius.

double radius = input.nextDouble();

Declare radius to be a double variable

double radius;

The _ type values are more accurate than the _ type values (float or double)

double, float

For example, the following statement imports all the classes from the package java.util.

import java.util.*;

Import the class Scanner (use the code instruction)

import java.util.Scanner;

draw with one line: int count; count = 1;

int count = 1;

Declare count to be an integer variable

int count;

draw with one line: int i = 1, int j = 2;

int i = 1, j = 2;

Declare i, j, and k as int variables on one line

int i, j, k;

The Scanner class is in the __.

java.util package

Java uses System.out to refer to the standard output device and System.in to the standard input device. By default, the output device is the display monitor and the input device is the _.

keyboard

A _ is a constant value that appears directly in a program.

literal

34 and 0.305 are _ in the following statements: int numberOfYears = 34; double weight = 0.305;

literals (numeric literals)

name variables and methods, naming convention

lowercase

A _ is an identifier that represents a permanent value.

named constant

The syntax _ creates an object of the Scanner type. The syntax Scanner input declares that input is a variable whose type is Scanner.

new Scanner(System.in)

reads an integer of the byte type.

nextByte()

reads a number of the double type.

nextDouble()

reads a number of the float type.

nextFloat()

reads an integer of the int type

nextInt()

reads an integer of the long type.

nextLong()

The method of reviewing how a program works is called _; helpful for understanding how programs work, and they are useful tools for finding errors in programs.

tracing a program

has only one operand; has two.

unary operator, binary operator

- operator in -5 is a _ operator to negate number 5, whereas the - operator in 4 - 5 is a _ operator for subtracting 5 from 4.

unary, binary

The syntax for assignment statements is as follows:

variable = expression;

The _ tells the compiler to allocate appropriate memory space for the variable based on its data type.

variable declaration

The _ import imports all the classes in a package by using the asterisk as the wildcard.

wildcard

reads an integer of the short type.

nextShort()

The information for the classes in an imported package is not read in at compile time or runtime unless the class is used in the program. The import statement simply tells the compiler where to locate the classes. There is _ between a specific import and a wildcard import declaration.

no performance difference

An identifier cannot be true, false, or _.

null

To improve readability, Java allows you to use underscores between two digits in a _. For example, the following literals are correct. However, 45_ or _45 is incorrect. The underscore must be placed between two digits.

number literal

An object may invoke its methods. To invoke a method on an object is to ask the object to _.

perform a task

Java provides _ primitive data types for numeric values, characters, and Boolean values.

8


Conjuntos de estudio relacionados

MOTIVATIONAL NEEDS AND PROCESSES

View Set

bio 1201 exam 1 practice and actual

View Set

Hinkle Chapter 54: Management of Patients With Kidney Disorder

View Set

EMT Chapter 34: Pediatric Emergencies

View Set

TIC: hálózatok, internet e-mail

View Set

Anthropology 1050 Exam 3 Study Guide Chapter 12

View Set

Unit 17 Leadership and Care Management

View Set

POL 120 TEST 2 Chapters 4,5,6+7 Study guide

View Set

MA LIFE INSURANCE EXAM STUDY GUIDE

View Set