Review 1 (Year 3 Sem 1)

Review 1 is the first review in semester 1 of year 3, and the first review in the total of year 3. It is a review for Introduction to Java & Programming in Java, and is considered to be easy.

Description
Please note that the purpose of Review Exercises is to prepare you for the WRITTEN TEST.

Hence, please do the questions after revising the topics, and think through the options properly.

You should NOT try to execute the code when attempting the questions.

Unlocked after completion

 * OCD (Score at least 60% for Review Exercise 1 [C1 & C2])
 * All reviewed (Score at least 80% for Review Exercise 1 [C1 & C2])
 * Getting Warmed Up (Score at least 80% for Review Exercise 1 [C1 & C2])

Question
Which of the following assignment statements is not valid?

Options
◻ int i = (int) 0.987;

◻ int j = 9.0;

◻ double d = 9;

◻ double e = (int) 9.87;

◻ long x = 98.7f;

◻ float y = 9.87;

Question
Which of the following are not legal identifiers in Java?

Options
◻ NUMBER_OF_MEMBERS_2008

◻ #OfMembers2008

◻ $NumberOfMembers2008

◻ 2008MembersNumber

◻ public

Question
Which of the following statement is true?

Options

 * An assembler interweaves the translation and execution activities of a program.
 * A Java .class file contains the source code.
 * The Java interpreter, also known as Java Virtual Machine (JVM), reads the machine code and executes the program on a specific machine.
 * String is considered an object type in Java.
 * Compile time error occurs during program execution.

Question
Write down the output after the following code segment is executed.

int x = 23; double y = 15.2; System.out.println("The value of x + y is " + x + y);

Question
Consider the following program:

import java.util.*; class Inputs { public static void main( String[] args ) { Scanner sc = new Scanner( System. in ); System. out .print( "Enter your name: " ); String n = sc.next; System. out .print( "Enter your age: " ); int a = sc.nextInt; System. out .print( "Enter your height (in cm): " ); double h = sc.nextDouble; System. out .println( n + ", " + a + ", " + h ); } // main } // Inputs

If the user intend to input the following:

Mary Smith

25 176

175.5

where indicates where the user intend to press the Enter key on the keyboard.

Which statement best describes what will happen when the program is executed with the above input?

Options

 * Mary Smith, 25, 176.0
 * Mary Smith, 25, 175.5
 * Mary, 25, 175.5
 * Program causes run-time error because there are too many inputs.
 * Program causes run-time error because some input is of the wrong data type.

Question
Write down the output after the following code segment is executed.

public class Output { public static void main(String args[]) { int i = 7 / 2 * ( 4 % 3 ) * 3 ; System. out .println(i); } }

Question
Write down the output after the following code segment is executed.

public class Output { public static void main(String args[]) { int a = 3 ; int b = a++ + --a; System. out .println(b); } }

Question
Write down the output after the following code segment is executed.

public class Output { public static void main(String args[]) { // Range of int is [-2147483648, 2147483647] int i = 2147483647 ; System. out .println(i + 1 ); } }

Question
What is the output of this program?

class Output { public static void main(String args[]) { try { int a = 0 ; int b = 5 ; int c = b / a;            System. out .print( "Hello" ); }        catch (Exception e){ System. out .print( "World" ); }    } }