chapter 8 Flashcards
(40 cards)
what type of variable is used to store a single character?
The Java type that’s used to store characters is char.
when you write a char type variable, what symbol surrounds the character?
In a Java program, every char literal starts and ends with a single quote mark.
why do you need to surround a char type variable with single a sing quote mark on each side?
When you surround a letter with quote marks, you tell the computer that the letter isn’t a variable name.
what are you telling the computer when you surround a letter with quote marks?
When you surround a letter with quote marks, you tell the computer that the letter isn’t a variable name.
what does the method whose name is Character.toUpperCase do?
the program calls an API method whose name is Character.toUpperCase. The method Character.toUpperCase does what it’s name suggests– the method produces the uppercase equivalent of a lowercase letter
what happens when you hand a program a capital letter and use the toUpperCase method?
nothing happens. you are returned a capital letter as before if you print it to the screen.
what happens if you feed the to UpperCase method a digit like 3?
nothing happens but if you print it out you recieve the same number 3.
when you are writing if there is something you don’t quite understand what should you do?
when you don’t understand something about computer programming, it often helps to write a test program. Make up an experiment and see how the computer responds.
why is it not a good idea to rely solely on the api document for answers?
because whatever the API answers, it ignores three other questions so be bold and don’t be afraid to tinker
what happens if you store more than 1 character in a char variable?
You can’t store more than one letter at a time in a char variable, and you can’t put more than one letter between a pair of single quotes.
what kind of variable do you need if you wanted to store more than 1 character in a variable?
If you’re trying to store words or sentences not just single letters, then you need to use something called a String.
when is the best time not to reuse a variable in your program?
in smaller program’s you do not need to reuse variables.
when is the best time to reuse a variable in your program?
in larger programs it’s better to reuse a variable because instead of hardcoding the variable again, you can simply summon an older version of that
how do you know when or when not to reuse variables?
it all depends on what you’re trying to do. the best way to know when or when not to reuse variables is by much practice.
g
what is it that the findWithinHorizon(“.”,0) method is looking for in the input?
using the findWithinHorizon(“.”,0) method looks for things in the input and depending on the stuff you put in parentheses.
what does \d in special code called and what does it stand for?
in special code it’s called a regular expression. it stands for a single digit.
when it comes to regular expressions, what does a dot mean?
a dot stands for any character at all.
when using the findWithinHorizon(“.”,0) method, what does the 0 stand for?
the 0 means for the method to keep seaching until the end of the input.
what does the paired combination of (“.”,0) tell the findWithinHorizon method?
it says to keep searching until any character that the user types on the keyboard.
why does the findWithinHorizon method, include the name Horizon for this method name?
because it searches as far as the method sees until it finds what is within the parentheses.
if your input for a findWithinHorizon (“\d\d\d”, 9) method is “Testing 1” or “Testing 123” doesn’t work then what needs number does the number 9 need to be altered to so that it won’t return null? and why? and if you printed the method input what would display if it worked?
you would need 3 consecutive digits not letters but the letters will only count as a number as well as spaces so you would have to change the 9 to 11 and it will not work with only one consecutive digit
What’s the role of charAt(0) in reading a single character?
it takes care of the multicharacter problem as it tells Java to pick the initial character from any of the characters that findWithinHorizon fetches.
how does writing input for two findWithinHorizon(“.”, 0) methods for 2 letters differ from inputing 2 numbers ?
when it comes to letters you don’t need to write a space but when it comes to numbers, you do need to space each number when you enter 2 or more amounts.
what happens when you call 2 findWithinHorizon(“.”, 0) methods and your input is “p o”, with a space between the “p” and the “o”?
the program will count the space as a character in your input