chapter 8 Flashcards
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.