Docsity

System.out.println(“ Ants”); ____ 4., Exams of Accounting

Toggle sidebar
bg1
Lesson 1 ...Quiz
Multiple Choice
Identify the choice that best completes the statement or answers the question.
____ 1. What is wrong with the following “skeleton” of a Java program?
public class MyClass
{
public static void main(String args[])
{
}
}
A. public and class on the first line should be interchanged
B. MyClass name is wrong
C. There should not be a [ ] after args
D. Nothing is wrong
E. None of these
____ 2. Which line of code will cause Hello to be printed?
A. System.out.println(“Hello”); D. All of these
B. System.out.println(Hello); E. None of these
C. System.out.println(“Hello”)
____ 3. What is actually printed with the following code?
System.out.print(“Fire”);
System.out.println(“ Ants”);
A. FireAnts D. Pants on fire
B. Fire Ants E. None of these
C. Fire
Ants
____ 4. What is the syntax for indicating that a line of text is not Java code; rather, it is a remark?
A. rem D. comment
B. \\ E. None of these
C. //
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19
pf1a
pf1b
pf1c
pf1d
pf1e
pf1f
pf20
pf21
pf22
pf23
pf24
pf25
pf26
pf27
pf28
pf29
pf2a
pf2b
pf2c
pf2d
pf2e
pf2f
pf30
pf31
pf32
pf33
pf34
pf35
pf36
pf37
pf38
pf39
pf3a
pf3b
pf3c
pf3d
pf3e
pf3f
pf40
pf41
pf42
pf43
pf44
pf45
pf46
pf47
pf48
pf49
pf4a
pf4b
pf4c
pf4d
pf4e
pf4f
pf50
pf51
pf52
pf53
pf54
pf55
pf56
pf57
pf58
pf59
pf5a
pf5b
pf5c
pf5d
pf5e
pf5f
pf60
pf61
pf62
pf63
pf64

Partial preview of the text

Download System.out.println(“ Ants”); ____ 4. and more Exams Accounting in PDF only on Docsity!

Multiple Choice Identify the choice that best completes the statement or answers the question.

____ 1. What is wrong with the following “skeleton” of a Java program?

public class MyClass { public static void main(String args[]) {

} }

A. public and class on the first line should be interchanged B. MyClass name is wrong C. There should not be a [ ] after args D. Nothing is wrong E. None of these

____ 2. Which line of code will cause Hello to be printed?

A. System.out.println(“Hello”); D. All of these B. System.out.println(Hello); E. None of these C. System.out.println(“Hello”)

____ 3. What is actually printed with the following code?

System.out.print(“Fire”);

System.out.println(“ Ants”);

A. FireAnts D. Pants on fire B. Fire Ants E. None of these C. Fire Ants

____ 4. What is the syntax for indicating that a line of text is not Java code; rather, it is a remark?

A. rem D. comment B. \ E. None of these C. //

Answer Section

MULTIPLE CHOICE

1. ANS: D PTS: 1

2. ANS: A PTS: 1

3. ANS: B PTS: 1

4. ANS: C PTS: 1

Answer Section

MULTIPLE CHOICE

1. ANS: D PTS: 1

2. ANS: C PTS: 1

3. ANS: B PTS: 1

4. ANS: E

...both B and C are illegal

PTS: 1

  1. ANS: F PTS: 1

Multiple Choice Identify the choice that best completes the statement or answers the question.

____ 1. What is output by the following code?

String s = “Mona Lisa”;

System.out.println(s.length( ));

A. 7 D. 9

B. illegal code E. None of these C. 8

____ 2. What is output by the following code?

String girl = “Heather Jones”;

System.out.println(girl.substring(8));

A. Heather (one space after the ‘r’) D. 8Jones B. er Jones E. None of these C. Jones

____ 3. What is output by the following code?

String girl = “Heather Jones”;

System.out.println(girl.substring(8,11));

A. Jon D. ather Jones B. one E. None of these C. ones

____ 4. What is the index of the ‘L’ in the String “Abraham Lincoln”?

A. 9 D. 0

B. 8 E. None of these C. 7

____ 5. What is output by the following code?

String s = “Beaver Cleaver”;

System.out.println(s.toUpperCase( ));

A. beaver cleaver D. eEAVER cLEAVER B. BEAVER CLEAVER E. None of these C. b

Multiple Choice Identify the choice that best completes the statement or answers the question.

____ 1. If int j = 3 , what will be the value of j++?

A. 4 D. 3.

B. 3 E. None of these C. 2

____ 2. What is another way to write p = p –1;?

A. p++ D. p + 1 B. ++p E. None of these C. 1 - p

____ 3. Write x += j; another way.

A. x = x + j; D. j = j + x; B. x + j = x; E. None of these C. x + x = j;

____ 4. Write code that is equivalent to saying the new value of w is the old value of w plus 6?

A. w = w + 6; D. Both A and B B. w += 6 E. Both B and C C. w++

____ 5. Which of the following is illegal?

A. x +=9; D. x = ++9; B. x = 9; E. More than one of these C. 9 = x;

Answer Section

MULTIPLE CHOICE

1. ANS: A PTS: 1

2. ANS: E

... answer is p-- or --p

PTS: 1

  1. ANS: A PTS: 1
  2. ANS: A PTS: 1
  3. ANS: E ... both C and D

PTS: 1

Answer Section

MULTIPLE CHOICE

1. ANS: C

... it would seem at first glance that A is illegal; however, 5/2 is done with integer arithmetic yielding an answer of 2.... and that’s legal to store in int i.

PTS: 1

  1. ANS: D PTS: 1
  2. ANS: E ... real answer is 8.

PTS: 1

  1. ANS: A PTS: 1

Multiple Choice Identify the choice that best completes the statement or answers the question.

____ 1. Show how we would calculate and print the square root of 139.

A. Math.sqrt(139.46); D. (139.46)^(1/2); B. println(sqrt(139.46)); E. None of these C. System.out.println(Math.sqrt(139.46));

____ 2. Show how we would print the value of pi (3.14159...).

A. System.out.println(PI.math); D. System.out.println(Math.pi); B. System.out.println(“pi”); E. System.out.println(Math.PI); C. System.out.println(PI);

____ 3. What would the following print if d = 208.4?

System.out.println(Math.ceil(d));

A. 209.0 D. 208

B. 209 E. None of these C. 208.

____ 4. Which line of code will calculate (3.1)4.052^ and store the result in double d.

A. double d = Math.pow(4.052, 3.1); D. double d = 3.1^(4.052) B. double d = Math.pow(3.1, 4.052); E. None of these C. double d = 3.1(pow(4.052));

Multiple Choice Identify the choice that best completes the statement or answers the question.

____ 1. What are the three data types that we are able to input from the keyboard?

A. int, data, server D. String, int, double B. String, document, file E. None of these C. picture, text, file

____ 2. Suppose a Scanner object, kb Reader , has already been created. Which line of code uses kbR eader to

input a number with “decimal places” from the keyboard and store the result in the variable, fract.

A. double fract = kbReader.nextDouble(); D. double fract = kbReader.nextDbl( ); B. double fract = kbReader.next( ); E. None of these C. double fract = kbReader.nextInt( );

____ 3. Suppose a Scanner object, kbReader , has already been created. Which line of code uses kbReader to

input a quantity like “Jo mamma” from the keyboard and store the result in the variable, name.

A. String name = kbReader.next( ); D. String name = kbReader.get( ); B. String name = kbReader.nextLine( ); E. More than one of these C. String name = kbReader.nextString( );

____ 4. Suppose a Scanner object, kbReader , has already been created. Which line of code uses kbReader to

input a number with “ no decimal places” from the keyboard and store the result in the variable,

count.

A. int count = kbReader.nextInt( ); D. int count = kbReader.next( ); B. int count = kbReader.nextInt; E. More than one of these C. int count = kbReader.nextDouble( );

Answer Section

MULTIPLE CHOICE

1. ANS: D PTS: 1

2. ANS: A PTS: 1

3. ANS: B PTS: 1

4. ANS: A PTS: 1

Answer Section

MULTIPLE CHOICE

1. ANS: B PTS: 1

2. ANS: E PTS: 1

3. ANS: B PTS: 1

4. ANS: A PTS: 1

5. ANS: B PTS: 1

6. ANS: B PTS: 1

Lesson 9 _Quiz

Multiple Choice Identify the choice that best completes the statement or answers the question.

____ 1. Which is the basic skeleton of an if - else structure?

A. if-else {

}

D. If( ) {

} {

} else

B. {if( )

} {else

}

E. None of these

C. If( ) {

} else {

}

____ 2. In the following code, assume that the portion designated with <#1> is a true statement. What will

be the output?

if( <#1> )

System.out.print(“Elvis”);

System.out.println(“ Presley”);

A. Elvis D. Presley (has a leading space) B. ElvisPresley E. None of these C. Elvis Presley

____ 3. In the following code, assume that the portion designated with <#1> is a false statement. What will

be the output?

if( <#1> )

Lesson 9 _Quiz Answer Section

MULTIPLE CHOICE

1. ANS: C PTS: 1

2. ANS: C PTS: 1

3. ANS: D PTS: 1

4. ANS: D PTS: 1

Multiple Choice Identify the choice that best completes the statement or answers the question.

____ 1. In a switch statement ( switch(???) ) what are the two type of variables that may be used in the area

designated by?

A. char, int D. String, int B. int, double E. char, String C. char, double

____ 2. What is the purpose of default in a switch structure?

A. Provides for error control B. Provide for anything not specifically covered by one of the cases C. Provides flow control D. default is not part of a switch structure E. None of these

int p = ??;

int x = 79;

switch(p)

case 1:

x = 20;

break;

case 2:

x = 2;

case 3:

x = 3;

default:

x ++;

____ 3. If p = 2 what is the final value of x in the code above?

A. 1 D. 4

B. 2 E. None of these C. 3

____ 4. If p = 1 what is the final value of x in the code above?

A. 18 D. 80

B. 20 E. 3

C. 22