java chapter 2

Pataasin ang iyong marka sa homework at exams ngayon gamit ang Quizwiz!

Which of the following is a valid Java statement? A) String str = 'John Doe'; B) string str = "John Doe"; C) string str = 'John Doe'; D) String str = "John Doe";

d) String str= "John Doe";

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

8

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

z=5.0

Which of the following is NOT a valid comment statement? A) // comment 1 B) /* comment 2 */ C) */ comment 3 /* D) /** comment 4 */

C) */ comment 3 /*

To compile a program named First, use the following command: A) java First.java B) javac First C) javac First.java D) compile First.javac

C) javac First.java

Which of the following does not describe a valid comment in Java? A) Single line comments, two forward slashes - // B) Multi-line comments, start with /* and end with */ C) Multi-line comments, start with */ and end with /* D) Documentation comments, any comments starting with /** and ending with */

C) multi-line comments, start with */ and end with /*

This is a variable whose content is read only and cannot be changed during the program's execution. A) operator B) literal C) named constant D) reserved word

C) named constant

This is a named storage location in the computer's memory. A) Literal B) Constant C) Variable D) Operator

C) variable

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

C) x = 37, y = 5

What will be displayed as a result of executing the following code? int x = 8; String msg = "I am enjoying java."; String msg1 = msg.toUpperCase(); String msg2 = msg.toLowerCase(); char ltr = msg.charAt(x); int strSize = msg.length(); System.out.println(msg); System.out.println(msg1); System.out.println(msg2); System.out.println("Character at index x = " + ltr); System.out.println("msg has " + strSize + " characters.");

I am enjoying java. I AM ENJOYING JAVA. i am enjoying java. Character at index x = o msg has 19 characters.

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

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

In Java, ________ must be declared before they can be used. A) variables B) literals C) key words D) comments

A) variables

Variables are classified according to their: A) value B) data type C) names D) location in the program

B) data type

A Java program must have at least one of these: A) Class definition B) Variable C) Comment D) System.out.println(); statement

A) class definition

In Java, it is standard practice to capitalize the first letter of: A) Class names B) Variable names C) Key words D) Literals

A) class names

The primitive data types only allow a(n) ________ to hold a single value. A) variable B) object C) class D) literal

A) variable

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

B) identifiers can contain spaces

Which of the following is valid? A) float y; y = 54.9; B) float y; double z; z = 934.21; y = z; C) float w; w = 1.0f; D) float v; v = 1.0;

C) float w; w=1.0f;

Given the declaration double r;, which of the following statements is invalid? A) r = 326.75; B) r = 9.4632e15; C) r = 9.4632E15; D) r = 2.9X106;

D) r=2.9X106;

What will be displayed as a result of executing the following code? int x = 6; String msg = "I am enjoying this class."; String msg1 = msg.toUpperCase(); String msg2 = msg.toLowerCase(); char ltr = msg.charAt(x); int strSize = msg.length(); System.out.println(msg); System.out.println(msg1); System.out.println(msg2); System.out.println("Character at index x = " + ltr); System.out.println("msg has " + strSize + "characters.");

I am enjoying this class. I AM ENJOYING THIS CLASS. i am enjoying this class. Character at index x = n msg has 25characters.

What will be displayed after the following statements have been executed? final double x = 99.0; x = 54.3; System.out.println("x = " + x );

Nothing, this is an error.

When saving a Java source file, save it with an extension of: A) .javac B) .class C) .src D) .java

D) .java

What is the result of the following expression? 25 / 4 + 4 * 10 % 3 A) 19 B) 5.25 C) 3 D) 7

D) 7

Which one of the following methods would you use to convert a string to a double? A) Byte.ParseByte B) Long.ParseLong C) Integer.ParseInt D) Double.ParseDouble

D) Double.ParseDouble

T/F: Class names and key words are examples of variables.

FALSE

Every Java application program must have: A) a class named MAIN B) a method named main C) comments D) integer variables

B) a method named main

Variables of the boolean data type are useful for: A) working with small integers B) evaluating true/false conditions C) working with very large integers D) evaluating scientific notation

B) evaluating true/false conditions

Which Scanner class method reads an int? A) readInt() B) nextInt() C) getInt() D) read_int()

B) nextInt()

When the + operator is used with strings, it is known as the: A) Assignment operator B) String concatenation operator C) Addition operator D) Combined assignment operator

B) string concatenation operator

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

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

Which of the following cannot be used as identifiers in Java? A) Variable names B) Class names C) Key words D) All of the above E) None of the above

C) key words

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

Nothing there is an error.

T/F: Both character literals and string literals can be assigned to a char variable.

FALSE

T/F: In Java the variable named total is the same as the variable named Total.

FALSE

T/F: Java is a case-insensitive language.

FALSE

T/F:A Java program will not compile unless it contains the correct line numbers.

FALSE

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 there is an error

T/F: Although the dollar sign is a legal identifier character, you should not use it because it is normally used for special purposes.

TRUE

T/F: Named constants are initialized with a value, that value cannot be changed during the execution of the program.

TRUE

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 BarbarianAdelle, the Alligator

In Java, the beginning of a comment is marked with: A) // B) "" C) ; D) #

A) //

To display the output on the next line, you can use the println method or use this escape sequence in the print method. A) \n B) \r C) \t D) \b

A) \n

Which of the following is NOT a primitive data type? A) short B) long C) float D) String

D) String

Which Scanner class method reads a String? A) readString() B) nextString() C) getString() D) nextLine()

D) nextLine()

T/F: All Java statements end with semicolons.

FALSE

T/F: Assuming that pay has been declared a double, the following statement is valid. pay = 2,583.44;

FALSE

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, there is an error

T/F: A variable's scope is the part of the program that has access to the variable.

TRUE

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

7

This is a value that is written into the code of a program. A) literal B) assignment statement C) variable D) operator

A) literal

The term ________ typically refers to the device that displays console output. A) standard output device B) central processing unit C) secondary storage device D) liquid crystal display

A) standard output device

The boolean data type may contain values in the following range of values: A) true or false B) -128 to + 127 C) - 2,147,483,648 to +2,147,483,647 D) - 32,768 to +32,767

A) true or false

In the following Java statement what value is stored in the variable name? String name = "John Doe"; A) John Doe B) The memory address where "John Doe" is located C) name D) The memory address where name is located

B) the memory address where "John Doe" is located

What is the result of the following expression? 10 + 5 * 3 - 20 A) -5 B) 5 C) 25 D) -50

b) 5

Which of the following statements correctly creates a Scanner object for keyboard input? A) Scanner kbd = new Scanner(System.keyboard); B) Scanner keyboard(System.in); C) Scanner keyboard = new Scanner(System.in); D) Keyboard scanner = new Keyboard(System.in);

C) Scanner keyboard= new Scanner(System.in);

Which one of the following would contain the translated Java byte code for a program named Demo? A) Demo.java B) Demo.code C) Demo.class D) Demo.byte

C) demo.class

Character literals are enclosed in ________; string literals are enclosed in ________. A) single quotes; single quotes B) double quotes; double quotes C) single quotes; double quotes D) double quotes; single quotes

C) single quotes; double quotes

What will be displayed after the following statements have been executed? int x = 15, y = 20, z = 32; x += 12; y /= 6; z -= 14; System.out.println("x = " + x + ", y = " + y + ", z = " +z);

C) x = 27, y = 3, z = 18

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

C) x=1,000


Kaugnay na mga set ng pag-aaral

Personal Finance 3.06 Quiz- Financial Planning

View Set

Week 6-7 Cranial Nerves - Lecture

View Set

Course 1 Week 2 - All About Analytical Thinking

View Set