wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

CF1 Quiz 3 - Java with Conditionals

Total questions: 117

Worksheet time: 1hrs 1mins

Name
Class
Date
1.

Name the data type that can store: "true"

a)

boolean

b)

char

c)

String

d)

double

2.

Name the data type that can store: 1.0

a)

double

b)

int

c)

char

d)

boolean

3.

Name the data type that can store: '3'

a)

int

b)

char

c)

String

d)

None of the above

4.

Name the data type that can store: false

a)

String

b)

boolean

c)

int

d)

None of the above

5.

What data type would you use for storing the number of students in a class?

a)

boolean

b)

String

c)

double

d)

int

6.

What data type would you use for storing the average test score in a class?

a)

double

b)

String

c)

int

d)

char

7.

What data type would you use for storing letter grades (without - or +) for students in a class?

a)

String

b)

char

c)

int

d)

boolean

8.

What data type would you use to store names of students?

a)

String

b)

char

c)

boolean

d)

None of these

9.

How would you declare and initialize a variable storing a person's name?

a)

string name = "Jeff";

b)

name String = "Jeff";

c)

String name = Jeff;

d)

String name = "Jeff";

10.

How would you declare and initialize a variable storing the tax rate?

a)

int taxRate = 5.1;

b)

taxRate = "5.1";

c)

double taxRate = 5.1;

d)

double taxRate = "5.1";

11.

How would you declare and initialize a variable that tells you that someone passed a class?

a)

boolean passed = 'true';

b)

boolean passed = true;

c)

passed = true;

d)

String passed = "true";

12.

Compute: 13%5=

a)

12

b)

2

c)

5

d)

3

13.

Compute: 7%11=

a)

0

b)

7

c)

11

d)

4

14.

What prints out "I love Java" successfully?

a)

System.out.println(I love Java);

b)

Systemoutprintln("I love Java);

c)

System.out.println("I love" + " Java");

d)

System.out.println("I love Java")

15.

Name the data type that can store: 5

a)

int

b)

char

c)

String

d)

None of the above

16.
A variable that holds a whole number
a)
String
b)
boolean
c)
int
d)
float
17.

A variable that holds words

a)

String

b)

boolean

c)

int

d)

float

e)

A dictionary

18.

A variable that holds true or false

a)

String

b)

boolean

c)

int

d)

float

e)

Alex Trebek

19.

Which declaration will throw an error?

a)

double num = 8;

b)

int averageGrade = 89.7;

c)

boolean done = false;

d)

String done = "true";

20.

_________ operator returns the remainder after division

a)

+

b)

/

c)

%

d)

*

21.

Main() method is not mandatory for a Java program

a)

True

b)

False

22.

Int data types represents _______ bits.

a)

8

b)

16

c)

32

d)

64

23.

Which of this command has errors? Select multiple

a)

System.out.print("Hello World")

b)

System.out.print(Hello World);

c)

System.out.Print("Hello World);

d)

System.out.print("Hello World");

24.

Which of the followings is Java code that starts from the main() method as a mandatory part of every program

a)

public void static main(String args [])

b)

public void main static (args[] String)

c)

public static void main (String args[])

d)

public static void main [String [] Args]

25.

It is an optional statement used to describe what a program or a line of program is doing.

a)

tag

b)

command

c)

code

d)

comment

26.

What data type is classified as a sequenced of characters with double quotes.

a)

Char

b)

String

c)

boolean

d)

Float

27.

True or False : Java is case sensitive, which means identifier Hello and hello would have different meaning in Java

a)

True

b)

False

28.

Which of the following primitive data type is a 1-bit and has only two values: true and false

a)

char

b)

string

c)

int

d)

boolean

29.
How many objects can be made from a class? 
a)
None, you make classes from objects
b)
one
c)
As many as you want
d)
All of the above
30.
What is the difference between a class and an object?
a)
A class is a blueprint to make an object
b)
An object is a blueprint to make a class
c)
A blueprint is an object to make a class
d)
Blueprint class is an object make a
31.
An object is an instance of a:
a)
parameter
b)
method
c)
class
d)
application
32.

How do you create a variable with the numeric value 5?

a)

float x = 5;

b)

x = 5;

c)

int x = 5;

d)

num x = 5

33.

How do you insert COMMENTS in Java code?

a)

# This is a comment

b)

/* This is a comment

c)

// This is a comment

34.

Java is short for "JavaScript".

a)

true

b)

false

35.

The value of a string variable can be surrounded by single quotes.

a)

true

b)

false

36.

In Java, everything is an Object. Java can be easily extended since it is based on the Object model. Which characteristic of Java was described?

a)

Object-oriented

b)

Simple

c)

Secure

d)

Robust

37.

What is the correct syntax to output "HelloWorld" in Java?

(a)  

38.

How do you write a Single Liner Comment in Java?

(a)  

39.

How do you create a variable with a numeric value 5. where the name of the variable is x.

(a)  

40.

(a)   binds the data and functions into single unit.

41.

Which operator is used to add together two values?

(a)  

42.

Which method can be used to find the length of a string?

a)

getSize()

b)

getLength()

c)

length()

d)

len()

43.

Which keyword is used to return a value inside a method?

a)

return

b)

void

c)

break

d)

get

44.

What will be the Output of the below code:

public class Demo{

public static void main(String[] args){

}

}

a)

a) Nothing

b)

b) Error

c)

C) Finite

d)

d) Hii

45.

Describe method.

a)

A component of a program in a big program.

b)

A program to perform a specific task.

c)

A component of a program written to perform a specific task.

d)

A variable that use to read an input.

46.

Which is the correct way to create a method header for a method called plusTwo that is accessible to other classes, returns and int, and takes a single int parameter?

a)

public void plusTwo(int myNumber)

b)

public void plusTwo()

c)

public int plusTwo( int myNumber)

d)

public static void plusTwo()

47.

Method make codes more readable and easier to debug.

a)

True

b)

False

48.

A method that does not return anything is :

a)

int

b)

double

c)

void

d)

public static

49.

Java is a true object-oriented language

a)

TRUE

b)

FALSE

50.

4 % 6

a)

4

b)

6

c)

2

d)

3

51.

6 % 4

a)

4

b)

6

c)

2

d)

3

52.

int a = 7;

int b = 2 + a;

a)

b = 9

b)

b = 2

c)

b = 7

d)

b = 5

53.

int a = 5;

a++;

What is a now?

a)

4

b)

7

c)

5

d)

6

54.

int a = 5;

a--;

What is a now?

a)

4

b)

3

c)

5

d)

6

55.

int x = 4;

x *= 10;

Which is true?

a)

x is now 40

b)

x is now 10

c)

x is still 4

d)

x is now 14

56.

What is the value of b after this code segment?

int a = 4;

int b = a++;

a = a * 2;

b /= 2;

a)

2

b)

4

c)

5

d)

8

57.

Is the below program correct to print "Hello World"

a)

True

b)

False

58.

Which is my className in the below program

a)

pack_2

b)

Basic

59.

(a)   number = 10;

60.

(a)   name = "ARMY";

61.

(a)   .out.println();

62.

(a)   number = "12345";

63.

Public static void (a)   (String[] args)

64.

(a)   Name = 120;

65.

Strings should always be compared in an if statement with a == symbol.

a)

TRUE

b)

FALSE

66.

=! is the symbol for “not equal”

a)

TRUE

b)

FALSE

67.

What is the output of the code shown in the image?

a)

False

b)

Next Round

c)

Game Finished

d)

finished

68.

Which statement(s) properly implements an equality comparison of two String objects?

a)

A, only

b)

B, only

c)

A and C

d)

All are acceptable

69.

Which of the following is used to assign a value to a variable?

a)

=

b)

==

c)

.equals()

d)

!=

70.

What is the output of the code shown?

a)

Sandy

b)

Squidward

c)

Patrick

d)

Spongebob

71.

What is the output of the code shown?

a)

Hello!!

b)

Goodbye!!

72.

Pieces of code that only run "under certain conditions":

a)

conditional statements

b)

control flow statments

c)

syntax

d)

variables

73.

What is a condition?

a)

JavaScript

b)

Something that has to be true in order for an action to be carried out.

c)

syntax

d)

pseudocode

74.

This is a catch-all for every other situation besides the one where the condition is true.

a)

then

b)

do

c)

else

d)

if

75.

A variable

a)

is a placeholder for a piece of information that can change.

b)

is like a bucket for holding information.

c)

can be written as letters or with longer words.

d)

all of these

76.

Which symbol means "not equal to"?

a)

==

b)

<=

c)

>=

d)

!=

77.

What is missing from the command: System.___.println("Hello World");

a)

prt()

b)

Sys

c)

java

d)

out

78.

Which is the correct way to end a command statement in Java?

a)

;

b)

,

c)

.

d)

:

79.

public void main()

{

double temp = 56.0;

if (temp <=54.0 && temp>40){

System.out.println(“It is too hot”);

}

else if ( temp<40 || temp>30){

System.out.println(“It is hot but not too much”);

}

else{

System.out.println(“It is pleasant”);

}

}

What will be the output?

a)

It is too hot

b)

It is pleasant

c)

It is hot but not too much

d)

runtime error

80.

PREDICT THE OUTPUT:

int x = 20;

int y = 18;

if(x>y){

System.out.println("x is greater than y");

}

else

{

System.out.println("Error");

System.out.println("Incorrect code");

}

a)

Error

b)

Incorrect code

c)

x is greater than y

d)

Error

Incorrect code

81.

int marks = 50;

if( marks > 70 ){

System.out.println("Distinction");

}

else if( marks > 35 ){

System.out.println("Pass");

}

else{

System.out.println("Fail");

}

a)

Pass

b)

Distinction

c)

Fail

d)

Pass

Fail

82.

What will be the output of following statement-

System.out.println('A'=='a');

a)

A==a

b)

65==97

c)

true

d)

false

83.

The if -else statement executes a block of code if a specified condition is

a)

true

b)

false

c)

both of these

d)

None of these

84.

What does the else do in Java?

a)

You put it after the If statement. If the statement is false then the program will run the code inside the else statement.

b)

If there is an else after the if then the condition is automatically false

c)

It tells the user to ignore the line immediately after

d)

It tells the computer to jump back up to line 1 of the program.

85.

What is/are true about pseudocode?

a)

somewhere between English and a coding language.

b)

more precise than English but less precise than a coding language.

c)

used by programmers to figure out the logic and flow of their programs without having to worry about syntax.

d)

all of these

86.

Which of these is a correct way of declaring an array of integers?

a)

int[] arrayA = new int[10];

b)

int arrayB = new int[20];

c)

int arrayC[] = int[30];

d)

int[] arrayD = new int[40]

87.

Suppose you create a typical array of Strings, containing the subjects you will see next year. Which of the following is NOT true.

a)

You may remove one of the subjects (it will be replaced by null).

b)

You may add another subject to the array.

c)

You may replace one subject with another one different.

d)

You may copy the contents of that array into another array with the same size.

88.

What is the output of this code inside the main method?

int[] myNums;

System.out.println(myNums[0]);

a)

null

b)

There's no output.

c)

An error appears.

d)

0

89.

What is the output of this code inside the main method?

int[] myNums = new int[3];

System.out.println(myNums[1]);

a)

null

b)

There's no output.

c)

An error appears.

d)

0

90.

What is the output of this code inside the main method?

String[] myWords = new String[5];

System.out.println(myWords[5]);

a)

null

b)

There's no output.

c)

An error appears.

d)

0

91.

What is the output of this code inside the main method?

String[] myWords = new String[5];

System.out.println(myWords[4]);

a)

null

b)

There's no output.

c)

An error appears.

d)

0

92.

Which of the following declares an array of integers named number?

a)

int number;

b)

int [ ] number;

c)

int new number [ ];

d)

int number = int [ ];

93.

What is the output of the following code fragments?

int [ ] fun = new int [5];    

fun[0] = 1;    

fun[1] = 2;    

fun[2] = 3;    

fun[3] = 4;    

fun[4] = 5;    

int j = 3;    

System.out.println(fun[ j-1]) ;

a)

1

b)

2

c)

3

d)

4

94.

What is the output of the following code fragment?    

int [ ] odd = {1, 3, 5, 7, 9, 11 };    

System.out.println( odd[0] + "  " + odd[3] ) ;

a)

1 5

b)

6

c)

1 7

d)

8

95.

For which of the following situations is only one array NOT appropriate?

a)

Working with 30 scores on the Java exam.

b)

Working with names and ages of students.

c)

Working with mileage during the weeks of vacation.

d)

Working with company monthly sales totals.

96.

What is the output of the following code fragment?     

int [ ] evens = {2, 4, 6, 8, 10};    

evens[0] = 44;    

evens[4] = evens[2];    

System.out.println(evens[0] + "  " + evens[4]);

a)

44 10

b)

2 10

c)

54

d)

44 6

97.

What are the indeces for this array?  int [ ] k = { 11, 12, 13, 14, 15};

a)

0, 1, 2, 3, 4

b)

1, 2, 3, 4, 5

c)

11, 12, 13, 14, 15

d)

10, 11, 12, 13, 14

98.

What is the output for the following code fragment?       

int [ ] car = new int [7];     

car[0] = 2004;     

car[1] = 2006;     

System.out.println(car[0] + " " + car[1] + " " car[7]);

a)

2004  2006  0

b)

2004  2006

c)

4010

d)

an error will occur

99.

What is the output for the following code fragment?       

int [ ] car = new int [7];     

car[0] = 2004;     

car[1] = 2006;     

System.out.println(car[0] + " " + car[1] + " " car[7]);

a)

2004  2006  0

b)

2004  2006

c)

4010

d)

an error will occur

100.

What is the length of this array?      

double[ ] stuff = {1.5,  2.5,  3.5,  4.5,  5.5,  6.5};

a)

1

b)

5

c)

6

d)

7

101.

Which of the following is FALSE about arrays on Java

a)

A java array is always an object

b)

Length of array can be changed after creation of array

c)

Arrays in Java are always allocated on heap

102.

Find the output

class Test {

public static void main(String args[]) {

int arr[2];

System.out.println(arr[0]);

System.out.println(arr[1]);

}

}

a)

Compile error

b)

Exception

c)

Garbage Value

Garbage Value

d)

0

0

103.

Find the output

class Test {

public static void main(String args[]) {

int arr [ ] = new int[2];

System.out.println(arr[0]);

System.out.println(arr[1]);

}

}

a)

Compile error

b)

Exception

c)

Garbage Value

Garbage Value

d)

0

0

104.

class Demo1

{

public static void main(String args[])

{

int i[] = new int[10];

System.out.println(i[10]);

}

}

a)

0

b)

Garbage Value

c)

Out-of-bounds exception

d)

Error

105.
_________________ is a collection of elements used to store the same type of data.
a)
Array
b)
Switch
c)
Case
d)
Loop
106.
How will you identify a single array?
a)
single curly brackets
b)
single square brackets
c)
multiple squares brackets
d)
single angled brackets
107.

Which of the following is true about a void method?

I. The method returns a boolean value

II. The method does not return any value

III. The method has a void return type

a)

I only

b)

II only

c)

III only

d)

I and II only

e)

II and III only

108.

A(n) ____ causes a value to be sent from a called method back to the calling method

a)

method statement

b)

return statement

c)

initialization

d)

assignment

109.

Maximum how many value a method may return?

a)

0

b)

1

c)

2

d)

infinite

110.

Can we use "void" and return together?

a)

Yes

b)

No

111.

How many return statements can be used in a method?

a)

0

b)

1

c)

2

d)

Any number of return statements

112.

What is the return type of a method that does not return any value?

(a)  

113.

What is the return type of the main() method?

(a)  

114.

If a function contains several return statement, how many of them will be executed?

a)

Only 1

b)

All

115.

A class object is also known as:

a)

Identifier

b)

Instance

c)

Specifier

d)

Modifier

116.

A class contains:

a)

Attributes and methods

b)

A number of object of same types

c)

Data and member function

d)

All of the above

117.

_______________ is the defined as the template/blueprint

a)

Object

b)

Method

c)

Class

d)

Data