powerpoint 2.txt

Card Set Information

Author:
dimeng
ID:
296407
Filename:
powerpoint 2.txt
Updated:
2015-02-21 08:24:22
Tags:
diane cs140
Folders:
diane,cs140
Description:
diane cs140 powerpoint2
Show Answers:

Home > Flashcards > Print Preview

The flashcards below were created by user dimeng on FreezingBlue Flashcards. What would you like to do?


  1. Name six flow chart elements.
    • Start (oval or dot)
    • Stop (oval or dot with circle around it)
    • statements rectangles
    • selection diamond
    • repetition diamond
    • order of activities arrow
  2. What are the possible values for the boolean data type?
    True and false
  3. Two operators look similar, = and ==. What are these?
    • = is assignment
    • == is comparison (is the value on the left equal to the value on the right?)
    • Don't use == for string values
  4. Comparison operators give a result of the __________ data type.
    boolean (true or false)
  5. Do you always need curly braces around the code executed if the condition is true in an if statement?
    No, if it is a single statement you don't need to use curly braces (but you can).
  6. What is the shorthand equivalent for this simple if statement in java? If (n1 > n2) max = n1; else max = n2;
    max = (n1 > n2)?n1:n2;
  7. What class and method can you call to terminate a program?
    • System.exit(argument);
    • where the argument is passed to the operating system. 0 indicates successful completion; anything else is an error code.
  8. What are the symbols for and, or and not?
    • and &&
    • or ||
    • not !
  9. What method should you use to compare strings?
    • .equals()
    • syntax: string1.equals(string2)
  10. What are the possible return values for the s1.compareTo(s2) method and what do they mean?
    • The method will compare the strings character by character until it reaches the end of both strings or an "inequality" and returns an integer:
    • 0 the strings are equal
    • <0 s1 is less than s2
    • >0 s1 is greater than s2
  11. If a = 5 and b = 3, what value does the following expression return: a > b && a > 4
    True (true and true = true)
  12. What is the difference between bitwise and logical (short-circuiting)?
    • When java is evaluating an and or or (&& or ||), it first evaluates the first condition (e.g. p1 && p2). In this case, if the first condition is false, it does not evaluate the second condition - this is called short circuiting. If the First condition is true, p2 will be evaluated.
    • If the second condition would fail at runtime (say, due to division by zero), short circuiting could prevent the runtime error and evaluate correctly.
    • The bitwise and and bitwise or operators are & and |.
  13. The logical OR (||) short circuits when the condition on the left is _________.
    true. Only one input is required to be true for an OR to evaluate as true.
  14. In order of operations, which is evaluated first: && or ||?
    &&
  15. What is the syntax for a switch statement?
    • switch ( or or ) {
    • case :
    • break;
    • case :
    • break;
    • default:
    • }
  16. What would happen if you forgot to issue a break at the end of a case within a switch staement?
    The next case would be ignored, and code would be executed until the next break statement.
  17. What type of if statement is the switch statement a good replacement for?
    if - else if - else
  18. What is the syntax for executing the same code for different constants in a switch statement?
    • switch (letterGrade) {
    • case 'A':
    • case 'a':
    • code to execute; break;
  19. What does the Math.random() method do?
    It returns a random number between 0 and 1.
  20. What does Math.max(num1, num2) do?
    Returns the larger of the two input numbers of the same type.
  21. What does Math.pow(num1, num2) do?
    It raises num1 to the power num2.
  22. What could you do to get a random number between 1 and 100?
    100*Math.random()
  23. What does str.toUpperCase() do?
    It converts the string str to uppercase and returns it.
  24. What does str.length() do?
    Returns the number of characters in the string str.
  25. What does this statement do? System.out.println (str.charAt (str.length))); ?
    Returns an error. The charAt method considers the first character to be in position 0, so there is no character in the position that is equal to the length of the string.
  26. What is the result of this statement? System.out.print (5 + "I am A strinG".(0)); ?
    The output is 78 because the charAt(0) returns the ASCII code for I which is 73.
  27. What is the result of this statement? System.out.print ("" + 5 + "I am A strinG".charAt(0) ); ?
    The output is 5I because the empty double quotes at the beginning typecasts the entire expression to a string.
  28. What does str.concat(stringArgument) do?
    It concatenates the stringArgument with str.
  29. How does s1.compareTo(s2) work?
    • The .compareTo() method will compare the first two distinct characters of s1 and s2 (from left to right). If the first distinct character in s1 is earlier in the Unicode character set than the corresponding character in s2, the value returned is equal to the difference between the unicode values and negative.
    • If the first distinct character in s1 is later in the Unicode character set than the corresponding character in s2, the value returned is equal to the difference between the unicode values and positive.
    • If the two strings are equal the method returns 0.
  30. What does s1.substring() do?
    • This method returns the substring of s1 starting at the position specified in the argument and continuing to the end of the string.
    • Remember that the first character in any string is position 0.
    • E.g. message = "Cockatiels are silly" message.substring(5) returns "tiels are silly"
  31. What does the .substring() method do if it has two arguments?
    It returns the string starting at the position of the first argument and ending at the position of the second argument.
  32. What does the .indexOf() method do?
    • It returns the position of the first occurence of the string specified in the argument.
    • e.g. message = "Cockatiels are silly" message.indexOf("tiels") returns 5.
  33. What does the .lastIndexOf() method do?
    • It returns the position of the last occurence of the string specified in the argument (or the first occurrence from the right).
    • e.g. message = "Cockatiels are silly" message.lastIndexOf('e') returns 13.
  34. To use a date object you must import which class?
    java.util.Date
  35. What is the syntax to declare a date object?
    Date variableDate = new Date();
  36. What is the default date format for a date object?
    Weekday Month Day hh:mi:ss CST yyyy

What would you like to do?

Home > Flashcards > Print Preview