Chapter 4 & 5 Review

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

prefix mode

++number; is an example of a statement that uses a increment operator in______________?

anywhere an int value can be used.

A call to an int value-returning method can be used

a new String object is created in memory.

Any time you use the = operator to assign a string literal to a String reference variable,

a parameter variable.

Attempting to use a local variable before it has been given a value will result in a compiler error, to avoid this in a method, you can initialize the variable using

is lost.

Between calls to a method, any value that is stored in a local variable

No, methods can only return one primitive type or object

Can a method return more than one type?

No

Can more than one item be returned in a method?

the benefit of using methods to write code once then reusing it each time you perform the task.

Code reuse refers to

have a datatype listed before its name.

Each parameter in a parameter list must

that only a copy of the argument's value is passed into a parameter value.

In Java, all arguments of the primitive type are passed by value, which means

only a copy of an arguments value is passed into a parameter variable.

In Java, all arguments of the primitive types are passed by value which means,

int, double, boolean, or any other valid data type.

In its header, a value returning method will have ____________ in the place of void.

No, only boolean expressions are allowed, though compound booleans are ok.

Is it possible to have multiple statements in the test section of a for loop?

yes. for (int i=0, j=42; i > 10; i++ j--)

Is it possible to have multiple statements within the Initialization and Update Expressions of a for loop?

yes. System.out.println("How many iterations do you want to run?"); iterations = stdin.nextInt(); for (i = 0, j = 42; i < iterations; i++) { total += (int)(Math.random() * 100 + 1); } System.out.println("Average = " + (total/iterations));

Is it possible to make a for loop a user-controlled loop?

widen, narrow

Java will automatically __________ the value of a return expression in a value returning method, but it will not _________ it.

that you can use the same name for methods as long as the arguments are different.

Method Overloading refers to the fact

break a problem into small, manageable pieces, sometimes called the divide and conquer approach. They allow scaling.

Methods are commonly used to

Integer.parse.Int , Math.pow

Some value-returning methods are:

System.out.println.

Some void methods we have used are:

they cannot be changed.

String objects in Java are immutable, which means

a method's local variable exists only while the method is executing.

The lifetime of a local variable refers to the fact that

functional decomposition.

The process of breaking down a problem into smaller piece is called

void methods and value returning methods.

Two categories of methods are

the calling method should have the same throws clause.

Until we learn how to handle exceptions, if a method calls another method that has a throws clause, then

arguments.

Values that are sent into a method are called

The header and the body

What are the two parts of a method?

it increments b by 1, then prints b, i.e. (b+1)

What does System.out.println(++b) do?

It prints a then increments a by 1.

What does System.out.println(a++) do?

It causes the program to exit the loop. They are usually considered taboo in a loop because they bypass the normal condition.

What does the break statement do inside a loop?

parameter

What is String str in the following statement? public static void printALine(String str) { System.out.println(str) ; }

argument

What is System.out.println(str) in the following statement? public static void printALine(String str) { System.out.println(str) ; }

method name

What is printALine in the following statement? public static void printALine(String str) { System.out.println(str) ; }

Modifiers Public refers to accessibility. Static refers to the fact that it is run only once.

What is public static in the following statement? public static void printALine(String str) { System.out.println(str) ; }

return type

What is void in the following statement? public static void printALine(String str) { System.out.println(str) ; }

Initialization -> Test -> Statements -> Update -> Test

What sequence do the 4 parts of a for statement execute in?

the javadoc utility will create a Returns section in the method's documentation.

When a method's documentation comments contain a @return tag,

If you need to use it after the loop, declare before.

When do you declare the variable within the Initialization Expression of a for loop and when do you not?

when the condition is false.

When does a program exit the while loop?

parameter variable.

You can design your own methods to accept data in a specific way by using a

return

You must have a __________ statement, in a value-returning method.

x = 2 and y = 2

int x = 1, y; y = ++x; after statements run, what are the values of x and y?

x = 2 and y = 1

int x = 1, y; y = x++; after statements run, what are the values of x and y?

postfix mode

number--; is an example of a statement that uses a decrement operator in______________?

Initialization, Test, Update, Statements.

what are the 4 parts of a for statement?

It causes the program to return to the test statement without finishing the next section of loop, after returning to the test it continues through the loop. It causes the current iteration to end immediately.

what does the continue statements do inside a loop?


Conjuntos de estudio relacionados

Texas Government 2306: Chapter 9, 10

View Set

ATI Fundamentals Final Exam (F1)

View Set

Chapter 25: Nursing Care of the Child With an Alteration in Immunity/Immunologic Disorder

View Set

STS General Concepts and STS Historical Development

View Set

CITI - Consent with Subjects Who Do Not Speak English

View Set