Font size
WorksheetsCF1 Quiz 3 - Java with Conditionals
Total questions: 117
Worksheet time: 1hrs 1mins
Name the data type that can store: "true"
boolean
char
String
double
Name the data type that can store: 1.0
double
int
char
boolean
Name the data type that can store: '3'
int
char
String
None of the above
Name the data type that can store: false
String
boolean
int
None of the above
What data type would you use for storing the number of students in a class?
boolean
String
double
int
What data type would you use for storing the average test score in a class?
double
String
int
char
What data type would you use for storing letter grades (without - or +) for students in a class?
String
char
int
boolean
What data type would you use to store names of students?
String
char
boolean
None of these
How would you declare and initialize a variable storing a person's name?
string name = "Jeff";
name String = "Jeff";
String name = Jeff;
String name = "Jeff";
How would you declare and initialize a variable storing the tax rate?
int taxRate = 5.1;
taxRate = "5.1";
double taxRate = 5.1;
double taxRate = "5.1";
How would you declare and initialize a variable that tells you that someone passed a class?
boolean passed = 'true';
boolean passed = true;
passed = true;
String passed = "true";
Compute: 13%5=
12
2
5
3
Compute: 7%11=
0
7
11
4
What prints out "I love Java" successfully?
System.out.println(I love Java);
Systemoutprintln("I love Java);
System.out.println("I love" + " Java");
System.out.println("I love Java")
Name the data type that can store: 5
int
char
String
None of the above
A variable that holds words
String
boolean
int
float
A dictionary
A variable that holds true or false
String
boolean
int
float
Alex Trebek
Which declaration will throw an error?
double num = 8;
int averageGrade = 89.7;
boolean done = false;
String done = "true";
_________ operator returns the remainder after division
+
/
%
*
Main() method is not mandatory for a Java program
True
False
Int data types represents _______ bits.
8
16
32
64
Which of this command has errors? Select multiple
System.out.print("Hello World")
System.out.print(Hello World);
System.out.Print("Hello World);
System.out.print("Hello World");
Which of the followings is Java code that starts from the main() method as a mandatory part of every program
public void static main(String args [])
public void main static (args[] String)
public static void main (String args[])
public static void main [String [] Args]
It is an optional statement used to describe what a program or a line of program is doing.
tag
command
code
comment
What data type is classified as a sequenced of characters with double quotes.
Char
String
boolean
Float
True or False : Java is case sensitive, which means identifier Hello and hello would have different meaning in Java
True
False
Which of the following primitive data type is a 1-bit and has only two values: true and false
char
string
int
boolean
How do you create a variable with the numeric value 5?
float x = 5;
x = 5;
int x = 5;
num x = 5
How do you insert COMMENTS in Java code?
# This is a comment
/* This is a comment
// This is a comment
Java is short for "JavaScript".
true
false
The value of a string variable can be surrounded by single quotes.
true
false
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?
Object-oriented
Simple
Secure
Robust
What is the correct syntax to output "HelloWorld" in Java?
(a)
How do you write a Single Liner Comment in Java?
(a)
How do you create a variable with a numeric value 5. where the name of the variable is x.
(a)
(a) binds the data and functions into single unit.
Which operator is used to add together two values?
(a)
Which method can be used to find the length of a string?
getSize()
getLength()
length()
len()
Which keyword is used to return a value inside a method?
return
void
break
get
What will be the Output of the below code:
public class Demo{
public static void main(String[] args){
}
}
a) Nothing
b) Error
C) Finite
d) Hii
Describe method.
A component of a program in a big program.
A program to perform a specific task.
A component of a program written to perform a specific task.
A variable that use to read an input.
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?
public void plusTwo(int myNumber)
public void plusTwo()
public int plusTwo( int myNumber)
public static void plusTwo()
Method make codes more readable and easier to debug.
True
False
A method that does not return anything is :
int
double
void
public static
Java is a true object-oriented language
TRUE
FALSE
4 % 6
4
6
2
3
6 % 4
4
6
2
3
int a = 7;
int b = 2 + a;
b = 9
b = 2
b = 7
b = 5
int a = 5;
a++;
What is a now?
4
7
5
6
int a = 5;
a--;
What is a now?
4
3
5
6
int x = 4;
x *= 10;
Which is true?
x is now 40
x is now 10
x is still 4
x is now 14
What is the value of b after this code segment?
int a = 4;
int b = a++;
a = a * 2;
b /= 2;
2
4
5
8
Is the below program correct to print "Hello World"
True
False
Which is my className in the below program
pack_2
Basic
(a) number = 10;
(a) name = "ARMY";
(a) .out.println();
(a) number = "12345";
Public static void (a) (String[] args)
(a) Name = 120;
Strings should always be compared in an if statement with a == symbol.
TRUE
FALSE
=! is the symbol for “not equal”
TRUE
FALSE
What is the output of the code shown in the image?
False
Next Round
Game Finished
finished
Which statement(s) properly implements an equality comparison of two String objects?
A, only
B, only
A and C
All are acceptable
Which of the following is used to assign a value to a variable?
=
==
.equals()
!=
What is the output of the code shown?
Sandy
Squidward
Patrick
Spongebob
What is the output of the code shown?
Hello!!
Goodbye!!
Pieces of code that only run "under certain conditions":
conditional statements
control flow statments
syntax
variables
What is a condition?
JavaScript
Something that has to be true in order for an action to be carried out.
syntax
pseudocode
This is a catch-all for every other situation besides the one where the condition is true.
then
do
else
if
A variable
is a placeholder for a piece of information that can change.
is like a bucket for holding information.
can be written as letters or with longer words.
all of these
Which symbol means "not equal to"?
==
<=
>=
!=
What is missing from the command: System.___.println("Hello World");
prt()
Sys
java
out
Which is the correct way to end a command statement in Java?
;
,
.
:
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?
It is too hot
It is pleasant
It is hot but not too much
runtime error
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");
}
Error
Incorrect code
x is greater than y
Error
Incorrect code
int marks = 50;
if( marks > 70 ){
System.out.println("Distinction");
}
else if( marks > 35 ){
System.out.println("Pass");
}
else{
System.out.println("Fail");
}
Pass
Distinction
Fail
Pass
Fail
What will be the output of following statement-
System.out.println('A'=='a');
A==a
65==97
true
false
The if -else statement executes a block of code if a specified condition is
true
false
both of these
None of these
What does the else do in Java?
You put it after the If statement. If the statement is false then the program will run the code inside the else statement.
If there is an else after the if then the condition is automatically false
It tells the user to ignore the line immediately after
It tells the computer to jump back up to line 1 of the program.
What is/are true about pseudocode?
somewhere between English and a coding language.
more precise than English but less precise than a coding language.
used by programmers to figure out the logic and flow of their programs without having to worry about syntax.
all of these
Which of these is a correct way of declaring an array of integers?
int[] arrayA = new int[10];
int arrayB = new int[20];
int arrayC[] = int[30];
int[] arrayD = new int[40]
Suppose you create a typical array of Strings, containing the subjects you will see next year. Which of the following is NOT true.
You may remove one of the subjects (it will be replaced by null).
You may add another subject to the array.
You may replace one subject with another one different.
You may copy the contents of that array into another array with the same size.
What is the output of this code inside the main method?
int[] myNums;
System.out.println(myNums[0]);
null
There's no output.
An error appears.
0
What is the output of this code inside the main method?
int[] myNums = new int[3];
System.out.println(myNums[1]);
null
There's no output.
An error appears.
0
What is the output of this code inside the main method?
String[] myWords = new String[5];
System.out.println(myWords[5]);
null
There's no output.
An error appears.
0
What is the output of this code inside the main method?
String[] myWords = new String[5];
System.out.println(myWords[4]);
null
There's no output.
An error appears.
0
Which of the following declares an array of integers named number?
int number;
int [ ] number;
int new number [ ];
int number = int [ ];
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]) ;
1
2
3
4
What is the output of the following code fragment?
int [ ] odd = {1, 3, 5, 7, 9, 11 };
System.out.println( odd[0] + " " + odd[3] ) ;
1 5
6
1 7
8
For which of the following situations is only one array NOT appropriate?
Working with 30 scores on the Java exam.
Working with names and ages of students.
Working with mileage during the weeks of vacation.
Working with company monthly sales totals.
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]);
44 10
2 10
54
44 6
What are the indeces for this array? int [ ] k = { 11, 12, 13, 14, 15};
0, 1, 2, 3, 4
1, 2, 3, 4, 5
11, 12, 13, 14, 15
10, 11, 12, 13, 14
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]);
2004 2006 0
2004 2006
4010
an error will occur
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]);
2004 2006 0
2004 2006
4010
an error will occur
What is the length of this array?
double[ ] stuff = {1.5, 2.5, 3.5, 4.5, 5.5, 6.5};
1
5
6
7
Which of the following is FALSE about arrays on Java
A java array is always an object
Length of array can be changed after creation of array
Arrays in Java are always allocated on heap
Find the output
class Test {
public static void main(String args[]) {
int arr[2];
System.out.println(arr[0]);
System.out.println(arr[1]);
}
}
Compile error
Exception
Garbage Value
Garbage Value
0
0
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]);
}
}
Compile error
Exception
Garbage Value
Garbage Value
0
0
class Demo1
{
public static void main(String args[])
{
int i[] = new int[10];
System.out.println(i[10]);
}
}
0
Garbage Value
Out-of-bounds exception
Error
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
I only
II only
III only
I and II only
II and III only
A(n) ____ causes a value to be sent from a called method back to the calling method
method statement
return statement
initialization
assignment
Maximum how many value a method may return?
0
1
2
infinite
Can we use "void" and return together?
Yes
No
How many return statements can be used in a method?
0
1
2
Any number of return statements
What is the return type of a method that does not return any value?
(a)
What is the return type of the main() method?
(a)
If a function contains several return statement, how many of them will be executed?
Only 1
All
A class object is also known as:
Identifier
Instance
Specifier
Modifier
A class contains:
Attributes and methods
A number of object of same types
Data and member function
All of the above
_______________ is the defined as the template/blueprint
Object
Method
Class
Data
