DOC PREVIEW
OSU CSE 1223 - Exam I

This preview shows page 1-2-3-4 out of 11 pages.

Save
View full document
Premium Document
Do you want full access? Go Premium and unlock all 11 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

Name CSE 1223 Exam I Autumn 2016 Instructions Do not open the exam before you are told to begin This exam is closed book closed notes You may not use any calculators or any other kind of computing device on this exam Direct all questions to the instructor and no one else You have 55 minutes to complete this exam When time is called you must lay down your pencil and submit the exam There are three parts to this exam containing questions worth a total of 100 points Not all questions are worth the same number of points You should scan the exam before starting The space allotted for each questions should provide more than sufficient space to answer the question If you find you are running out of space you are probably on the wrong track Part Score I 30 II 41 III 29 TOTAL 100 In accordance with The Ohio State University Code of Student Conduct I certify that I have received no aid on this exam from any other person I have not given anyone aid on this exam I shall NOT discuss the contents of this exam with anyone who has not already taken this exam Signed Part I Coding 30 points 1 13 points Complete the following program skeleton for the program Exam1A given below This program should ask the user to enter a String It should report the length of the String Then it should ask the user to enter a second String and report the length of that String It should then concatenate the two strings together with the longer string coming first and the shorter string coming second and display that to the screen Make sure your code produces the same output as that given in the transcript below You should get the input using the Scanner method nextLine See the last page of the exam for reminders of what these Scanner methods and String methods do Here is a sample transcript of how the program should work Input typed by the user is indicated by bold text Enter a string Hello String has length 5 Enter another string Goodbye String has length 7 Concatenated together GoodbyeHello import java util Scanner public class Exam1A public static void main String args Scanner in new Scanner System in your code goes here CSE 1223 EXAM I Page 2 of 11 2 17 points Complete the following program skeleton for the program Exam2B given below This program should ask the user to enter a String and should loop until the user enters an empty String If the user has entered at least one String the program should report the longest and shortest strings entered by the user Make sure your code produces the same output as that given in the transcript below for the input given in the transcript below You should get the input using the Scanner method nextLine See the last page of the exam for a description of the nextLine method and some String methods that may be useful Here is a sample transcript of how the program should work Input typed by the user is indicated by bold text Enter a value My Enter a value Good Enter a value Friend Enter a value Longest String Friend Shortest String My import java util Scanner public class Exam2B public static void main String args Scanner in new Scanner System in your code goes here CSE 1223 EXAM I Page 3 of 11 Part II Short Answer 41 points 3 Complete the tracing table below as discussed in class and in the course notes Make sure you trace every variable through every statement that is executed and indicate any iterations where code is skipped by drawing a line or leaving a blank 10 points Code State Variable Values x 3 while x 2 0 x if x 5 x x x 2 x else x x x 2 x x x CSE 1223 EXAM I Page 4 of 11 4 Consider the two code segments below a and b where x and y are int variables a if x y b if x y x x 2 x x 2 else if x y y y 3 y y 3 Will these two code segments always produce the same assignments for x and y in the end or are there certain values of x and or y where they will behave differently If you believe that they will behave the same way provide a convincing argument in 1 2 sentences to explain why you believe that this is so If you believe that they will behave differently provide at least one example of values for x and y where they behave differently and describe the difference 3 points Given the following declarations determine the type e g int boolean String double or char and value of each of the expressions listed below For example if the expression were 6 3 the type would be int and the value would be 9 2 points each double pi 3 14 String foo Autumn2016 int i 7 j 3 boolean x true y false 5 CSE 1223 8 foo length i 6 6 x y 9 foo charAt 3 7 j pi 10 i j EXAM I Page 5 of 11 Consider the following code segment where x is a variable of type int if x 55 if x 80 System out println Fruit Custard else System out println Brownies else if x 22 if x 60 System out println Espresso Cake else System out println Apple pie else if x 25 System out println Dark Chocolate Cake else System out println Cherry Pie For each of the following output values give the range of values for the variable x that will cause the segment to display the given String For example if anything between 0 and 10 including both 10 and zero will produce the string your answer should be 0 x 10 If a value can never be produced by this code give a short single sentence explanation of why not 2 points each 11 Apple pie 12 Brownies 13 Cherry Pie 14 Dark Chocolate Cake 15 Espresso Cake 16 Fruit Custard CSE 1223 EXAM I Page 6 of 11 For the questions below use the following variable declarations As a reminder strictly larger or smaller than x means that x is not included and strictly between x and y means that the value is between x and y but does not include x and y 2 points each int count max min boolean stop pause end String foo bar 17 Write a while condition for a loop that runs as long as max is strictly greater than min and also less than the length of the string bar while 18 Write a while condition for a loop that runs as long as stop is false min is strictly less than 6 and the character at position 3 in the String bar is not a q while Part III Multiple Choice 29 points For each of the following questions circle the single answer that BEST answers the question 2 points each 19 Which …


View Full Document

OSU CSE 1223 - Exam I

Download Exam I
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Exam I and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Exam I and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?