

Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
A part of the lecture notes for csis 110, covering topics related to decisions and switch statements. It includes information on 'if statement gotcha's', switch statements, and equality testing of objects. Students are reminded of an upcoming quiz and programming assignment.
Typology: Study notes
1 / 3
This page cannot be seen from the preview
Don't miss anything!


Reminder: Quiz Wednesday. Reading Assignment Chapter 5, sections 5.5 through 5.8. Programming Assignment The next programming assignment is on-line. Although it is not due until next Monday the 14th, I strongly recommend working on it before the quiz, as it will increase your understanding of conditional logic. Chapter 5: Decisions Review If statement "gotcha's"
switch (
Case choices must be integral values - you can't put Strings, or floats, or boolean expressions here. *** End of Review *** Equality Testing of Objects If we want to see if two ints have the same value, we can use the == operator: int value1 = stdin.nextInt(); int value2 = stdin.nextInt(); if ( value1 == value2 ) S.O.PL( "value1 is equal to value2"); else S.O.PL( "value1 is not equal to value2" ); Tempting to do the same thing with Strings - Let's look at StringCompare.java String firstString = stdin.nextLine(); String secondString = stdin.nextLine(); if ( firstString == secondString ) S.O.PL( "The Strings are the same"); else S.O.PL( "The Strings are different" ); Let's look at another example (modify StringCompare to add thirdString): String firstString = stdin.nextLine(); String secondString = stdin.nextLine(); String thirdString = firstString; if ( firstString == secondString ) S.O.PL( "The Strings are the same"); else S.O.PL( "The Strings are different" ); if ( firstString == thirdString ) S.O.PL( "The Strings are the same"); else S.O.PL( "The Strings are different" ); So, what is == testing? It is checking to see if the references are the same. Do the Strings refer to the same memory location?