NEW
Font size
WorksheetsAP CSA Unit One Review
Total questions: 23
Worksheet time: 12mins
Which of the following answer choices display the correct format for a Java main class?
public static void main(String [] args)
public void main static(String [] args)
public static main static(String [] args);
public static void main static(Int [] args)
public static main static(String {} args);
Which of the following answer choices shows the output of the following snippet of code?
System.out.print(“Welcome back”);
System.out.println(“IA!”);
System.out.println(“Hope you had a great summer!”);
Welcome back IA! Hope you had a great summer!
Hope you had a great summer!
Welcome back IA!
Welcome back IA!
Hope you had a great summer!
Welcome backIA
Hope you had a great summer!
Welcome back IA!Hope you had a great summer!
Which of the following is NOT a Java Primitive Data Type
String
double
integer
char
boolean
True or False: This code will run with no errors
public class QuizOne
{
public static void main(String[]args)
{
System.out.println(“Today is Monday”)
}
}
True
False
Which of the following lines of code will print “Hello IA” to the console
System.out.print(“Hello IA”)
System.out.println(“Hello IA”);
System.outprint(Hello IA);
System.out.println(Hello IA)
Assuming this code has a main class and runs with no errors, what will be the output on the console:
double z = 6.7;
int x = 4;
int y = 8;
z = x/y;
System.out.println(z);
0.5
0
0.0
2
2.0
What is the primary use of the Scanner class in Java?
To generate random numbers
To create graphical user interfaces
To read input of primitive data types and strings
To manage database connections
To handle file input/output
How do you correctly create a Scanner object in Java
Scanner myObj = new Scanner()
Scanner myObj = new Scanner(java.util.Scanner)
Scanner myObj = new Scanner(System.out)
Scanner myObj = new Scanner(System.in)
Scanner myObj = new Scanner(InputStream)
Which method is used to read a string value using the Scanner class?
nextLine()
nextInt()
nextString()
nextLn()
nextStr()
What does the method nextLine() do in the Scanner class
Reads a Boolean value
Reads a String value
Reads an Int value
Reads a Double value
Reads a Float value
Which of the following is not a method of the Scanner class for reading specific data types?
nextInt()
nextFloat()
nextChar()
nextBoolean()
nextByte()
What does the Scanner class do with an input line such as “How are you”?
Divides it into numbers
Splits the line into tokens
Converts it into an array
Reads it as a single integer
Ignores any whitespace characters
What is the difference between .equals() and ==
== is an operator that compares the references or memory addresses of objects to determine if they are the same, whereas . equals() is a method that compares the contents of the objects to check for value equality
equals() is a method that compares the references or memory addresses of objects to determine if they are the same, whereas == is a operator that compares the contents of the objects to check for value equality
A method must be declared within a _____________.
variable
object
main
class
What will be the output of the following code snippet?
int a = 5;
int b = 10;
System.out.println(a + b);
15
510
5 + 10
Compilation Error
What will be the output of the following code snippet?
int x = 7;
int y = 3;
System.out.println(x % y);
1
2
3
4
Which of the following is the correct way to declare a constant in Java?
final int MAX_VALUE = 100;
const int MAX_VALUE = 100;
int const MAX_VALUE = 100;
int MAX_VALUE = 100;
What will be the output of the following code snippet?
String str = "Hello";
str += " World";
System.out.println(str);
Hello
Hello World
World
Compilation Error
What will be the output of the following code snippet?
int a = 10;
int b = 3;
System.out.println(a / b);
3.3333
3
3.0
Compilation Error
What will be the output of the following code snippet?
String s1 = "Hello";
String s2 = "Hello";
System.out.println(s1 == s2);
true
false
Compilation Error
Runtime Error
Which of the following is the correct way to create an object of the class 'Car' in Java?
Car myCar = new Car();
Car myCar = Car();
Car myCar = new Car;
Car myCar = Car.new();
What will be the output of the following code snippet?
int a = 5;
int b = 2;
System.out.println(a * b);
10
7
3
2.5
What will be the output of the following code snippet?
String str = "Hello";
System.out.println(str.length());
4
5
6
7
