Java

Ace your homework & exams now with Quizwiz!

The difference between a "while" and a "do while" is:

All of these *The "do-while" checks the condition after the statements run, the "while" does it before. *The "do-while" guarantees execution at least once, the "while" does not *The "do-while" has a semi-colon at the end, the "while" does not.

The statement or group of statements in a loop to be repeated is called the ____________ of the loop.

Body

Escape characters allow the programmer to indicate where to stop the execution of the program by escaping to the operating system.

False

If you use an if statement you must always include an else part

False

The index of the last character in a string is equal to the length() method's result.

False

When a list of statements is enclosed in parenthesis ( ), they form a single compound statement.

False

You can use a subtraction operator (minus sign) to get a sub-string from a larger string, for example: result = "Hello" - "H"; would set the variable result equal to "ello"

False

in a do-while loop the first thing that is checked is the boolean expression followed by the loop body

False.

A class type, unlike a primitive type, has both data and methods that take actions.

True

A loop continues executing a set of instructions until the controlling expression becomes false

True

Are these two sets of code equivalent? // the first one if(true) System.out.println("It was true"); System.out.println("Rest of the program"); // the second one if(true) { System.out.println("it was true"); } System.out.println("Rest of the program");

True

As far as the compiler is concerned, the level of nesting of code structures is given by the nesting of braces {} and not by the level of indentation

True

If you need to validate that two Boolean expressions are both true, you would use && to join them into a single Boolean expression.

True

If you want to execute multiple statements in an else portion of an if/else, you must enclose the statements in curly braces

True

Named constants are declared and initialized:

Within the class but outside of any methods, including main

You can make a string be an empty string by setting it equal to zero.

false

When the programmer knows exactly how many iterations a loop has to go through in their code which loop is best used?

for

if you were checking whether a user entered a valid test score, what would you use?

if (grade >= 0 && grade <= 100)

Which of the following is not a loop type?

if/else

If a variable is local to a loop then that variable will not exist outside the loop

true

We can always obtain the first character of a string S by using an expression S.substring(0,1)

true

It is possible for the body of the while loop to never run.

True

The equality Boolean operator (==) cannot be used to test if two objects have the same value

True

What will be printed by the following code? for(int count=0; count < 3; count++) { System.out.print("x"); }

xxx

Which logical operator does Java evaluate first, && or ||?

&&

In a string containing 5 characters, the last character is at index...

4

What will be printed by the following code? int i = 5; while (i >= 4) { System.out.println(i); i--; }

5 4

?

A java file contains a Class, which contains a main method, which contains instructions, which contains variables


Related study sets

Career Cluster Business Management and Administration

View Set

APCSP mid term exam 기출문제

View Set

Financial Leverage & Risk Analysis

View Set