Programming Java Chapter 2

Ace your homework & exams now with Quizwiz!

If you wish to use the System.out.printf method to print a string argument, use the ___ format specifier

%s

Which of the following is not a valid Java comment?

*/ Comment /*

Which of the following is not a valid comment statement? -// comment 1 -/* comment 2 */ -*/ comment 3 /* -/** comment 4 */

-*/ comment 3 /*

When saving a Java source file, save it with an extension of

.java

In Java, the beginning of a comment is marked with: - // - "" - ; - #

//

What is the result of the following expression? 10 + 5 * 3 - 20

5

What will be the value of z as a result of executing the following code? int x = 5, y = 28; float z; z = (float) (y / x);

5.0

What will be the value of z as a result of executing the following code? int x=5, y=28; float z; z=(float)(y/x);

5.0

What is the result of the following expression? 25 / 4 + 4 * 10 % 3

7

What is the result of the following expression? 17 % 3 * 2 - 12 + 15 -7 -8 -12 -105

7

What is the result of the following expression? 25 - 7 * 3 + 12 / 3 6 8 10 12

8

What will be the value of z after the following statements have been executed? int x=4, y=33; double z; z=(double)(y/x);

8.0

A Java program must have at least one -Class definition -Variable -Comment -System.out.println(); statement

Class definition

In Java, it is standard practice to capitalize the first letter of: -Class names -Variable names -Key words -Literals

Class names

Variables are classified according to their

Data type

Which one of the following would contain the translated Java byte code for a program named Demo? -Demo.java -Demo.code -Demo.class -Demo.byte

Demo.class

Variables of the boolean data type are useful for

Evaluating conditions that are either true or false

Both character literals and string literals can be assigned to a char variable

False

Which of the following is not a rule that must be followed when naming identifiers? -The first character must be one of the letters a-z, A-Z, and underscore or a dollar sign. -Identifiers can contain spaces. -Uppercase and lowercase characters are distinct. -After the first character, you may use the letters a-z, A-Z, the underscore, a dollar sign, or digits 0-9.

Identifiers can contain spaces

Which of the following cannot be used as identifiers in Java? -Variable names -Class names -Key words -All of the above -None of the above

Key words

This is a value that is written into the code of a program -literal -assignment statement -variable -operator

Literal

What will be displayed as a result of executing the following code? public class test { public static void main(String[] args) { int value1 = 9; System.out.println(value1); int value2 = 45; System.out.println(value2); System.out.println(value3); value = 16; } }

Nothing, this is an error

What will be the displayed when the following code is executed? final int x = 22, y = 4; y += x; System.out.println("x = " + x + ", y = " + y);

Nothing, this is an error

What will be displayed when the following code is executed? final int x = 22, y= 4; y += x; System.out.println ("x = " + x + "y = " + y);

Nothing. There is an error in the code

What would be printed out as a result of the following code? System.out.println("The quick brown fox" + "jumped over the \n" "slow moving hen."); -The quick brown fox jumped over the \nslow moving hen. -The quick brown fox jumped over the slow moving hen. -The quick brown fox jumped over the slow moving hen. -Nothing. This is an error.

Nothing. This is an error.

Character literals are enclosed in ___, and string literals are enclosed in ____

Single quotes, double quotes

The term ___________ typically refers to the device that displays console output. -Standard output device -Central processing unit -Secondary storage device -Liquid crystal display

Standard output device

Which of the following is not a primitive data type? -short -long -float -String

String

When the + operator is used with strings, it is known as the: -Assignment operator -String concatenation operator -Addition operator -Combined assignment operator

String concatenation operator

To print "Hello, world" on the monitor, use the following Java statement -SystemOutPrintln("Hello, world"); -System.out.println{"Hello, world"} -System.out.println("Hello, world"); -Print "Hello, world";

System.out.println("Hello, world");

In the following Java statement what value is stored in the variable name? String name="John Doe";

The memory address where "John Doe" is located

If the following Java statements are executed, what will be displayed? System.out.println("The top three winners are\n"); System.out.print("Jody, the Giant\n"); System.out.print("Buffy, the Barbarian"); System.out.println("Adelle, the Alligator"); -The top three winners are Jody, the Giant Buffy, the Barbarian Adelle, the Alligator -The top three winners are Jody, the Giant\nBuffy, the BarbarianAdelle, the Alligator -The top three winners are Jody, the Giant\nBuffy, the BarbarianAdelle, and the Albino -The top three winners are Jody, the Giant Buffy, the BarbarianAdelle, the Alligator

The top three winners are Jody, the Giant Buffy, the BarbarianAdelle, the Alligator

What would be displayed as a result of the following code? int x = 578; System.out.print("There are " + x + 5 + "\n" + "hens in the hen house.");

There are 5785 hens in the hen house

Named constants are initialized with a value and that value cannot change during the execution of the program: True or False

True

The System.out.printf method allows you to format output in a variety of ways

True

When you call one of the Scanner class's methods to read a primitive value, such as nextInt or nextDouble and then call the nextLine method to read a string, an annoying and hard-to-find problem can occur

True

The primitive data types only allow a(n) ___ to hold a single value

Variable

This is a named storage location in the computer's memory

Variable

This is a named storage location in the computer's memory. -Literal -Constant -Variable -Operator

Variable

In Java, ___________ must be declared before they can be used. -Variables -Literals -Key words -Comments

Variables

The simplest way you can use the System.out.printf method is

With only a format string, and no additional arguments

Which of the following statements will correctly convert the data type if x is a float and y is a double?

X=(float)y;

To display the output on the next line, you can use the println method or use this escape sequence in the print method.

\n

Every Java application program must have -a class named MAIN -a method named main -comments -integer variables

a method named main

Which of the following statements is invalid?

double r = 2.9X106;

Variables of the boolean data type are useful for -working with small integers -evaluating true/false conditions -working with very large integers -evaluating scientific notation

evaluating true/false conditions

Which of the following is valid? -float y; y = 54.9; -float y; double z; z = 934.21; y = z; -float w; w = 1.0f; -float v; v = 1.0;

float w; w = 1.0f;

To compile a program named First, use the following command: -java First.java -javac First -javac First.java -compile First.javac

javac First.java

Given the declaration double r;, which of the following statements is invalid? r = 326.75;b. r = 9.4632e15; r = 9.4632E15; r = 2.9X106;

r = 2.9X106;

The boolean data type may contain values in the following range of values true or false -128 to + 127 - 2,147,483,648 to +2,147,483,64. - 32,768 to +32,767

true or false

If x has been declared an int, which of the following statements is invalid? x = 0; x = -58932; x = 1,000; x = 592;

x = 1,000;

What will be displayed as a result of executing the following code? int x = 5, y = 20; x += 32; y /= 4; System.out.println("x = " + x + ", y = " + y); -x = 32, y = 4 -x = 9, y = 52 -x = 37, y = 5 -x = 160, y = 80

x = 37, y = 5

What output will be displayed as a result of executing the following code? int x =5, y = 20; x+= 32; y/=4; System.out.println("x=" + x + ", y=" +y);

x=37,y=5


Related study sets

Ch. 41 Musculoskeletal care modalities

View Set

Chapter 12 - Emerging Technologies: Blockchain and AI Automation

View Set

GLOBAL ENVIRONMENT OF BUSINESS chapter 1-2

View Set

Payroll Accounting: Employee Earnings and Deductions

View Set

CCNA Routing and Switching: Scaling Networks Chapter 2

View Set

MICRO Lab Practical #2 (will continue to update)

View Set