CSCI 675 - Java Practice Exam

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

What is the value of x after the execution of the following line of code? int x = (int) (Math.random()*100); Answers: 1 A random integer between 0 and 99, inclusive Syntax Error A random integer between 1 and 100, inclusive Response Feedback: Student shall know the methods in Math class. For instance, sqrt, pow, floor, ceil, random, etc

A random integer between 0 and 99, inclusive

What is the output of the following code? Answers: 9 0 There is a syntax error 21

9

What is the output of the following code if the value of score is 100? Assume variables score and grade has been declared as int and char, respectively. Answers: There is a compile error in line 19 U A There is a compile error in line 21

A

What will be the output of following piece of code? System.out.println("/"Hello World/""); Answers: "Hello World" Run time error Syntax Error Hello World Response Feedback: The students shall know the escape characters. \n, \t, \", and \\

Syntax Error

What is the output of the following Java program? Answers: Compile error in line 5 Compile error in line 4 Good Morning Compile error in line 6

Good Morning

Suppose in.txt contains one line of data: "Hello World". What will be the content of out.txt after execute the following Java program. Suppose open file to read and open file to write both successfully. Answers: Hello World HELLO WORLD Compile Error Nothing

HELLO WORLD

What is the output of the following Java code segment? StringBuilder s = new StringBuilder("Hello"); s.replace(1, 7, "World"); //1 System.out.println(s); Answers: HWorldo Compile error in line //1 HWorld StringIndexOutOfBoundsException at line //1

HWorld

What is the output of the following code if user typed: Hello World then hit Enter Key? Scanner input = new Scanner(System.in); String greeting = input.nextLine(); System.out.println(greeting); Answers: There is run time error Hello There is a syntax error Hello World

Hello World

What is the output of the following code if user typed: 1 2 3 then hit Enter Key? (there are spaces between numbers) Scanner input = new Scanner(System.in); int x = input.next(); System.out.println(x); Answers: 123 There is a syntax error There is run time error 1

There is a syntax error

What is the output of the following code? BigDecimal d1 = new BigDecimal("1.11"); BigDecimal d2 = new BigDecimal("2.22"); System.out.println(d1 + d2); Answers: 1.11+2.22 1.112.22 There is a syntax error 3.33 Response Feedback: Student shall know the BigInteger and BigDecimal classes, which belong to java.math package.

There is a syntax error

Assume char c = 'A'; Which of the following change value of c to 'a'? Answers: Character.toLowerCase(c); c = c.toLowerCase(); c.toLowerCase(); c = Character.toLowerCase(c); Response Feedback: Student shall know all eight wrapper classes in Java

c = Character.toLowerCase(c);

What is the output of the following Java progam? Answers: true Compile error in line 10 false Compile error in line 4

false

Suppose I have the following Scanner object: File file = new File("data.txt") Scanner input = new Scanner(file); After I read data from file, which of the following close the file? Answers: file.close() input.close(); input.close(file); file.close(input); Response Feedback: Student shall know how to create and use a Scanner object to read from a file

input.close();

BigInteger class belongs to which of the following package? Answers: java.util java.lang java.io java.math Response Feedback: Students shall know the often used classes and their packages. For instance, System, Math, String, Scanner, Integer (and other seven wrapper classes), BigInteger, BigDecimal.

java.math

What will the output in file data.txt after we execute the following Java program? Answers: nothing in file Compile error in line 5 Hello World HelloWorld

nothing in file

Which of the following is the correct head of main function in java? Answers: public static void main(String args) public static int main(String [] args) public void main(String [] args) public static void main(String [] args) Response Feedback: Student shall know the head of main function, which is an entry point of a project

public static void main(String [] args)

Suppose we have Random rand = new Random(); Which of the following expression generates a random integer between 20 and 100, inclusive? Answers: rand.nextInt() % 81 + 20 rand.nextInt() % 80 + 20 rand.nextInt() % 81 rand.nextInt() % 80 Response Feedback: Student shall know how to use random method in Math class and nextInt, nextDouble methods in Random class to generate random numbers in give range.

rand.nextInt() % 81 + 20

What is the output of the following Java progam? Answers: Compile error in main function true Compile error in line 7 false

true

What is the output of the following Java code? Answers: Compile error in mySwap method x = 20 y = 10 x = 10 y = 20 Compile error in main method

x = 10 y = 20

What will the output in file data.txt after we execute the following Java program? Answers: Compile error in line 3 HelloWorld Compile error in line 5 Hello World nothing in file

Compile error in line 3

What is the output of the following code? Answers: x = 10 y = 20 x = 20 y = 10 Compile error(s) in mySwap method Compile error(s) in main method

Compile error(s) in main method

What is the output of the following code? public class MyClass{ private int x; public void output() { System.out.println(x); } public static void main(String [] args) { MyClass myClass = new MyClass(); // 1 myClass.output(); // 2 } } Answers: 0 Compile error at line // 1 garbage value Compile error at line // 2 Response Feedback: Unlike class members, local variables of methods must be assigned a value to before they are accessed, or it is a compile error.

0

What is the output of the following Java code? Answers: 1 compile error at line 3 compile error at line 6 compile error at line 7

1

What is the output of the following Java code? Answers: 0 Compile error in line 6 Compile error in line 10 100

100

What is the output of the following Java progam? Answers: Run time except at line 8 2 99 Compile error in line 9 Compile error in line 8

2

What is the output of the following code if user's input is 8? Answers: 2 0 1 There is a compile error in code

2

What is the output of the following Java program? Answers: There is a compile error There is a run time exception 2, 3 1, 2

2, 3

What is the output of the following code? Answers: There is a syntax error in line 10 15 There is a syntax error in line 12 20

20

What is the output of the following Java program? Answers: -1 There is run time error since the array to be searched is not sorted 4 There is compile error

4

What is the output of the following code segment? int x = (int) 5.6789; System.out.println(x); Answers: 6 There is a compile error There is a run time error 5

5

What is the output of the following code segment? char c = 'A'; System.out.println(c+32); Answers: c32 There is a compile error 97 a

97

What is the output of the following code? Answers: Compile error in line 16 Base::fun() called Compile error in line 8 Derived::fun() called

Base::fun() called

Which of the following method is NOT a method in Double class? Answers: double valueOf(String) String toString() static Diouble valueOf(double) static Diouble valueOf(String) Question 35 0.5 out of 1 points Which of the following return true if char c is an English letter. Assume that c has been initialized. Answers: Character.isLetterOrDigit(c) Character.isDigit(c) Character.isAlpha(c) Character.isLetter(c)

Character.isLetter(c)

What is the output of the following Java code segment? int arr[2]; System.out.println(arr[0]); System.out.println(arr[1]); Answers: Compile error 0 0 garbage value garbage value Running time Exception

Compile error

What is the output of the following Java code segment? String s = "Hello"; // 1 System.out.println(s.size()); // 2 Answers: Compile error in line // 1 5 6 Compile error in line // 2

Compile error in line // 2

What is true about the following Java code segment? Answers: There is no compile error Compile error in line 6 Compile error in line 10 Compile error in line 11

Compile error in line 11

What is true about the following Java program Answers: There is a compile warning message indicates that one catch clause can never be reached. However, the program still can run and the output will be: Caught derived class exception Compile error in line 9 There is no compile warning or error. The output will be: Caught derived class exception Compile error in line 12

Compile error in line 12

What is the output of the following Java program? Answers: Compile error in line 15 Grandparent Parent Child Grandparent Child Compile error in line 23

Compile error in line 15

What is the output of the following code? Answers: Compile error in line 16 Compile error in line 15 Base::fun() called Derived::fun() called

Derived::fun() called

What is the output of the following Java program? Answers: Divide by zero error inside the finally block Divide by zero error inside the finally block 0, Divide by zero error inside the finally block

Divide by zero error

What is the output of the following Java program? Answers: Run time exception Compile error in line 6 0 MyClass@xxxxxxxx where xxxxxxxx is some hexadecimal number

MyClass@xxxxxxxx where xxxxxxxx is some hexadecimal number

What is the outcome of the following code? class Main { public static void main(String args[]) { int x = 0 ; int y = 10 ; System.out.println( y/x); } } Answers: 0 10 Compile error No compile error but will throw ArithmeticException exception

No compile error but will throw ArithmeticException exception

What is the output of the following code if the value of score is 78? Assume variable score and grade has been declared as int and char, respectively. Answers: There is a compile error in line 11 C There is a compile error in line 12 U

U

What is the output of the following Java program? Answers: a = 20 a = 10 Compile error in line 17 Compile error in line 23

a = 20


Kaugnay na mga set ng pag-aaral

NR599 Nursing Informatics: Mid Term_2021

View Set

Chapter 2: Reading/Study Guide Terms Review

View Set

Chapter 9: Other Health Insurance Concepts

View Set

CompTIA Security+ Exam SY0-501 Wireless Security Quiz

View Set