PracticeE2-Ans

PracticeE2-Ans - Exam 2 Review Last Name:_ First Name...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
Exam 2 Review Last Name:__________________ First Name _________Date____ Q. 1. What does the following code fragment write to the monitor? int depth = 8 ; if ( depth >= 8 ) { System.out.print("Danger: "); System.out.print("deep water. "); } System.out.println("No swimming allowed."); a. Danger: b. Danger: deep water. c. deep water. No swimming allowed. d. Danger: deep water. No swimming allowed Ans: d Q.2. What does the following code fragment write to the monitor? int depth = 12 ; int temp = 42 ; System.out.print("The water is: ") if ( depth >= 8 ) System.out.print("deep "); if ( temp <= 50 && depth <= 12) System.out.print("cold "); System.out.println(" wet."); Ans: The water is deep cold wet Q.3 Examine the code in each row. Decide if the printed output will be true or false. Point pointA = new Point( ); Point pointB = new Point( 0, 0 ); System.out.println( pointA == pointB ); _Ans: __ False ___________ Point pointA = new Point( 21, 17 ); Point pointB = pointA; System.out.println( pointA == pointB ); _______Ans: true____ Point pointA = new Point( 21, 17 ); Point pointB = new Point( 21, 17 ); System.out.println( pointA == pointB ); ___________Ans: false
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
The type char is a primitive data type ___Ans: true______________ The type String is a primitive data type __Ans: false______________ Q.4 Consider the following code: String str1 = “Java is fun”; String str2 = “Java is fun”; if ( ________________ ) System.out.println(“String1 and String2 are same”); else System.out.println(“String1 and String2 are different”); Fill out the missing if condition. Ans: str1.equals(str2)
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 6

PracticeE2-Ans - Exam 2 Review Last Name:_ First Name...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online