Download ReviewForTestMonFeb1

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project

Document related concepts

Law of large numbers wikipedia , lookup

Principia Mathematica wikipedia , lookup

Elementary mathematics wikipedia , lookup

Transcript
Read Module 2 pgs 41-80
1. What are data types and why are they important? Pg 43 boolean, char double int This prevents
errors and enhances reliability. String is not considered one of the basic data type (it’s a whole set of
characters enclosed by double quotes)
2. What are Java’s eight simple types of data? Pg 43 boolean (true, false), [byte, short, int, long] (diff
types of intergers), char (characters), double, float (decimal or floating pt numbers)
3. What are the four integer types and what size of numbers can each hold? Byte -128 to 127, short,
int, long
4. How many bits is a byte of data? 8 bits
5. Which integer type holds the biggest integers? long
6. How would you represent the number 3 11 in binary? How about 5? 101
7. What is the decimal equivalent of 00010110? What about 00101011?
1X2^4 + 1X2^2 + 1X2^1 = 16 + 4 + 2 = 22,
1X2^5 + 1X2^3 + 1 X 2^1 + 1 X2^0 =
32 + 8 + 2 + 1 = 43
8. How can you get the value of Pi in Java? How about the square root function? How about the sine
of a number? Math.PI
Math.sqrt(7)
Math.sin(0.4), don’t forget, with trig functs, value
has to be in radians
9. If you are finding a cosine of an angle in Java, does the angle have to be in radians or
degrees?radians
10. Suppose you have the values x in degrees, and y in radians. How can you change x to radians and
y to degees?
Answer = Math.toRadians(x);
Answer = Math.toDegrees(y);
11. How can you create an object called fourDecimal to format a number to four decimal places?
DecimalFormat fourDecimal = new DecimalFormat("0.0000");
12. Use the object called fourDecimal in a print statement to format a variable called x
System.out.println(“The answer is “ + fourDecimal.format(x));
13. What are the two types of floating point or decimal types? And what size of numbers can they
hold? (need to look up on internet; values on pg 45 are wrong) float and double pg 45 (book is wrong)
biggest is double
14. What is Unicode and what is ASCII? Unicode is a code to represent all characters found in the
human language, ascii is a subset of Unicode and it handle the characters we use
15. What is the decimal value of a 97? and A65? What about z122, and Z90?
16. How can you ring the bell on the computer? System.out.println((char)7);
17. How can you find the numerical value of the character e if it’s held in the variable data? (int)data;
18. Which data type does Java use to define characters? char
19. Write a Java statement to define a character variable called data, and set it equal to the value of Z
char data = ‘Z’;
20. Write a Java statement to see if the variable data (from above) matches the letter A
if (data = = ‘A’) etc
21. What values does the Boolean type of data represent in Java? true or false
22. What is a Literal?pg 51, a fixed value, example 100, 0.5 it’s a constant
23. What number system uses base 16?pg 52 hexadecimal
24. What is a String Literal in Java? A set of characters enclosed by double quotes, “this is a test”
25. Write a Java statement to define a string variable answer and set it equal to the value of Brown
String answer = “Brown”;
26. Write a Java statement to see if the variable answer (from above) matches Black
if(answer.equals(“Black”));
27. What are the Arithmetic Operators in Java? See pg 60 + - etc What is 10%3? Gives 1
28. How do you use increment and decrement? Pg 62 x = x+1 same as x ++ If x = 20, what is y =
++x, y =21 or y = x-- y = 20, x is 19 after the fact ? y = x++
y is still 20, x still goes up to 21
29. What are relational and logical operators in Java?pg 63, Relational ==, !=, >, <, >=, <=
Logical &, |, &&, ||, ^ , !
30. What does short circuit logical operator mean? It stops checking an expression, once an answer
can be determined
31. What Java character is used for an assignment?= What is used to check if two items have the
same value?= = (double equal)
31. What is a short hand assignment? Way to speed up the typing of a program If x = 3, what does
x *=10 do to the value of x? 30, If y = 5, what is y-=2? y = y – 2 = 3
32. What is casting and what does (int) (25/3) result in? 8 forcing an answer to be of a certain type
33. What is scope? What variable are accessible to which parts of a program Suppose I define a
variable called x within a block of code. Can the main program print out the value for x? NO
see pg 56 Scope determines what objects or variables are visible to other parts of your program.
34. What are the relational operators verses the logical operators? > < != ect, logical ! && || see 29
above
35. Order the follow operators in terms of precedence: ++, (), && see pg 74 () ++ &&
36. Write a loop (in short had notation) to print the numbers from 1 to 100 for( i = 1; i<= 100; i++)
37. Write a piece of Java code to see if a variable x is between 4 and 25 if( i > 4 && i < 25)
38. Fill in the following truth table. Use 1 for true, 0 for false
A
B
A&B A|B A^B
!(A&B)
!(A|B)
0
0
0
0
0
1
1
0
1
0
1
1
1
0
1
0
0
1
1
1
0
1
1
1
1
0
0
0
!(A&B) | !(A|B)
1
1
1
0
39. If x = 19 and y = 2, decide if the following are true, false, or invalid Java statements
a. if (x <= y) False b. if (x*2 != y) True c. if (x-1 == y*9) True d. if (x => y) Not valid should
be >= e.if (y < x < 25) Not valid if(y < x && x < 25)
40. How can you find the square root of a number x in Java? Math.sqrt(x);
41. If you are using an expression like y = Math.sin(x); what are the units for x? radians
42. If you are doing integer math, what is the value of 5/2? 2
43. What symbols are used to increment in Java? ++ What about decrement? –
44. What is the scope of a variable? It refers to where a variable can be seen by other parts of the
program. If a variable is defined within a block, it cannot be seen outside of the block.
45. What is the symbol for short circuit AND? &&. TH short circuit OR is ||
46. What is the number 10/3 as an integer? 3
47. How could you generate random numbers between 1 and 52 inclusive (including 1 and 52)?
(int)(52*Math.random()) + 1;
48. What does the term casting mean? Forcing data to be of a certain type , example (int)(45/2) would
have the value 22
49. If the letter X has a value of 88, what is the value of Z? 90 since it’s 2 more down from X
50. What is (3+2)/5 + [ 8 + (4/2)]/5 ?? Answer 3