Programming Java Chapter 2

Lakukan tugas rumah & ujian kamu dengan baik sekarang menggunakan Quizwiz!

//

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

Data type

Variables are classified according to their

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

Class definition

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

False

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

Single quotes, double quotes

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

a method named main

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

r = 2.9X106;

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;

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

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

x = 1,000;

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

%s

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

Variables

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

Class names

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

The memory address where "John Doe" is located

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

True

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 or false

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

Variable

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

With only a format string, and no additional arguments

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

Standard output device

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

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

Literal

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

javac First.java

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

\n

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

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

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";

Evaluating conditions that are either true or false

Variables of the boolean data type are useful for

evaluating true/false conditions

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

8

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

7

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

5

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

7

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

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);

Nothing, this is an error

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; } }

x = 37, y = 5

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

Nothing. There is an error in the code

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, 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);

8.0

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);

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 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);

There are 5785 hens in the hen house

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.");

Nothing. This is an error.

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.

.java

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

String concatenation operator

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

Key words

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

String

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

Identifiers can contain spaces

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.

*/ Comment /*

Which of the following is not a valid Java comment?

-*/ comment 3 /*

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

float w; w = 1.0f;

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;

double r = 2.9X106;

Which of the following statements is invalid?

X=(float)y;

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

Demo.class

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


Set pelajaran terkait

Money and Banking Econ 315 Final

View Set

Florida DMV Learner's Permit Test

View Set

World History A CP-Unit 4 Review

View Set

Physics 221 Exam 2 Review Questions

View Set

Article 300. General Requirements for Wiring Methods and Materials

View Set

Sadlier Unit 1 Synonyms / Antonyms

View Set

Prefixes that Pertain to Numbers and Amounts

View Set