Download here

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
no text concepts found
Transcript
ANSWERS
ANSWERS FOR LECTURE PORTION
1.
2.
3.
4.
5.
6.
int i0;
myDouble = 5.0;
float myFloat = 4.0F;
Scanner keyboard = new Scanner (System.in);
String lastName = “”; OR String lastName = new String(“”);
System.out.println(“What is your last name?”); (Could be anything of that sort but make
sure you have your syntax correct)
7. lastName = keyboard.next();
8. lastName = lastName.toUpperCase();
9. keyboard.close();
10. int i1 = (int)c1;
11. a. System.out.printf(“%.6f”, d0); //will give you 4.000000
b. System.out.printf(“%.6f”, d1); //will give you 9.000000
c. System.out.printf(“%.6f”, d2); //will give you 9.000346
12. ||
13. ==
14. Use the .equals method
15. Answers
a. No (it’s an if, else if statement)
b. Yes (age >9) is exclusive of 9 and (age >= 10) is inclusive of 10
c. No, == vary rarely returns true even if the strings are exactly the same. (USE
.EQUALS)
16. Answers
a. Wow good job!
b. Java is cool
c. Yeah java is super-de-duperty cool
d. Nothing is printed from this if statement
17. Yes
18. |4|
19. |10| (The set of N includes 0)
20. |9| (The set of Z+ does not include 0)
21. |10|
22. Answers below
a. {-1,1}
b. {-1,1}
c. {1}
d. {} or Ø
e. {1, 4, 9, 16, 25, 36,49, 64, 81}
23. Answers below
a. A = |3|, B = |7|
b. A U B = {3, 4, 5, 6, 7, 8, 9, 11}
c. Intersection of A and B = {4, 5}
d. A – B = {8}
e. B – A = {3, 6, 7, 9, 11}
f. C – A = {}
g. Complement of B = {1,2,8, 10, 12,…}
24. Math.floor() is NOT one-to-one nor is it strictly increasing (however, it is increasing).
25. f(x) = x2 is NOT one to one nor is it strictly increasing/decreasing.
26. f(x) = x2, x <= 0 IS a one-to-one function and it is strictly decreasing (because of the
change in domain, WATCH OUT FOR THOSE)
27. 0
28. 0
29. 1
30. 0
31. Answers below:
a. mum
b. Marley (substring can work with only one number in the parenthesis, the
substring takes that as the starting point and then continues till the end of the
string)
c. Error/Doesn’t compile
d. u
e. o
f. error
g. -1 (doesn’t error)
h. -1 (doesn’t error)
i. 10
j. Bob Marleymummies
k. 0
l. 17
32. Answers: (Question #: is not printed from console and is there for clarification)
Question
Question
Question
Question
Question
Question
Question
Question
1:
2:
3:
4:
5:
6:
7:
8:
They aren't equal!
5.90000
3.0
4.000000
9.000000
9.000346
b
c1 = b
c1 = c
Question
Question
Question
Question
Question
Question




c1 = d
c1 is not a, b, c, or d
9: i0 = 3
10: i1 = 8
11: i2 = 100
12: s0 = Java
13: s1 = java
14: a
HINTS/TRICKS TO BE AWARE OF
Be careful when reading if statements for:
Be careful when answering discrete math questions:
o There are times when > and >= cause the same result
 Ie int age = 8; if (age >7) and if (age >= 8)
o Remember that || means that only ONE statement has to be true for the whole
statement to be true
o Remember that && means that BOTH statements must be true for the
statement to be true
o Remember that ! means NOT
When reading through code and writing the output:
o Write your variables on the side and as your variables change, you change your
list on the side.
o BEWARE of missing brackets
 In an unbracketed - if statement returns true, it will only compute the
first line of code underneath the if statement.
 ie:
if if (s0.equals(s1)){
System.out.println("They are equal");
}
else
System.out.println("They aren't equal!");
s1 = s1.toLowerCase();
**Only the “They aren’t equal!”) will print, s1 WILL NOT be
changed.
o That one variable/input can trigger multiple if statements
o That one variable/input can only trigger ONE statement in an if, else if, else
o That without an “else” there are times where NOTHING is triggered.
On your in lab coding quiz:
o Make sure you can do all of the homeworks and recitations without looking on
the internet or past assignments/labs.
o Make sure you know how to initialize a scanner and how to close it
 Format:
 To initialize: Scanner name = new Scanner (System.in);
 To close: name.close();

o Utilize Eclipse, it helps to figure out bugs (just hover over the underlined red or
click on the red x on the side). If you forgot some of the Scanner methods or the
String methods, Eclipse also helps give options (ie typing “name.” would list
things like name.next(), name.nextInt(), name.nextLine(), name.close(), etc)
Under the CS 160 Resources page, you can find a printf reference and an ASCII chart,
there is also tutorials and interactive discrete math practice quizzes under the
“Tutorials” tab.
o http://www.cs.colostate.edu/~cs160/.Spring16/home_resources.php
o http://www.cs.colostate.edu/~cs160/.Spring16/resources/Java_printf_method_
quick_reference.pdf
o http://www.cs.colostate.edu/~cs160/.Spring16/resources/asciiTable.pdf