ics 111 midterm 1 review. this class is ics111 1.true 2.false
Post on 20-Dec-2015
225 views
TRANSCRIPT
ICS 111ICS 111Midterm 1 ReviewMidterm 1 Review
1 2
0%
100%
This class is ICS111This class is ICS111
1. True2. False
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
21 22 23 24 25 26 27 28 29 30
1 2
0%
100%
Variable names should be Variable names should be descriptive and readabledescriptive and readable
1. True2. False
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
21 22 23 24 25 26 27 28 29 30
1 2 3 4 5
67%
20%
0%7%7%
line of Java code line of Java code “// System.out.println("Hello");” “// System.out.println("Hello");” willwill
1. do nothing2. cause "Hello" to be output3. cause a syntax error4. cause "(Hello)" to be output5. there is no way to know
without executing this line of code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
21 22 23 24 25 26 27 28 29 30
1 2 3 4
33%
7%
27%
33%
Is this a valid Java Is this a valid Java identifier?identifier?RESULTRESULT1. Yes2. No3. Yes but it doesn’t
follow the Java coding standards
4. What is an identifier?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
21 22 23 24 25 26 27 28 29 30
1 2 3
15% 15%
69%
Is this a valid Java Is this a valid Java identifier?identifier?black&whiteblack&white
1. Yes2. No3. Yes but it doesn’t
follow the Java coding standards
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
21 22 23 24 25 26 27 28 29 30
The The // // comment runs to the end comment runs to the end of the line only.of the line only.
38%
63%
1
2
1. Yes2. No
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
21 22 23 24 25 26 27 28 29 30
1 2 3
17%
0%
83%
What output is produced by What output is produced by the following statement?the following statement?System.out.println(“50 plus 25 ” + 50+25);System.out.println(“50 plus 25 ” + 50+25);
1. 50 plus 25 50252. 50 plus 25 753. There will be an
error
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
21 22 23 24 25 26 27 28 29 30
1 2 3
7%0%
93%
What output is produced by What output is produced by the following statement?the following statement?System.out.println(“50 plus 25 ” + (50+25));System.out.println(“50 plus 25 ” + (50+25));
1. 50 plus 25 50252. 50 plus 25 753. There will be an
error
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
21 22 23 24 25 26 27 28 29 30
1 2 3 4 5
9%
0%
9%9%
73%
What value is contained in the int What value is contained in the int variable size after this is variable size after this is executed:executed:size = 18;size = 18;size = size + 12;size = size + 12;size = size/4;size = size/4;1. This will generate
an error2. 303. 74. 7.35. 8
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
21 22 23 24 25 26 27 28 29 30
1 2 3 4
0%8%
85%
8%
What value is contained in the float What value is contained in the float variable depth after the following variable depth after the following statements are executed?statements are executed?depth = 2.4;depth = 2.4;depth = 20 – depth;depth = 20 – depth;
1. 172. 183. 17.64. There will be an
error
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
21 22 23 24 25 26 27 28 29 30
1 2 3 4 5
0% 0%
20%
0%
80%
int iResult;int iResult;int num1 = 25;int num1 = 25;int num4 = 5;int num4 = 5;iResult = num1/num4;iResult = num1/num4;
1. 42. 4.03. 54. 05. No idea
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
21 22 23 24 25 26 27 28 29 30
1 2 3 4 5
0%
21%
7%
71%
0%
int iResult;int iResult;int num1 = 25;int num1 = 25;int num4 = 5;int num4 = 5;iResult = num4/num1;iResult = num4/num1;
1. 42. 0.23. 54. 05. No idea , again…
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
21 22 23 24 25 26 27 28 29 30
1 2 3 4 5
0%
31%
13%
0%
56%
float fResult = 0;float fResult = 0;int num1 = 25;int num1 = 25;int num4 = 5;int num4 = 5;fResult = num1/num4;fResult = num1/num4;
1. 42. 4.03. 54. 05. error
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
21 22 23 24 25 26 27 28 29 30
1 2 3 4 5
0% 0%9%
91%
0%
float fResult = 0;float fResult = 0;int num1 = 25;int num1 = 25;int num4 = 5;int num4 = 5;fResult = num4/num1;fResult = num4/num1;
1. 42. 4.03. 54. 05. error
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
21 22 23 24 25 26 27 28 29 30
1 2 3 4 5
0% 0%
56%
33%
11%
float fResult = 0;float fResult = 0;int num1 = 25;int num1 = 25;int num4 = 5;int num4 = 5;fResult = (double)num4/num1fResult = (double)num4/num1;;
1. 42. 4.03. 54. 05. error
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
21 22 23 24 25 26 27 28 29 30
float fResult = 0;float fResult = 0;int num1 = 25;int num1 = 25;int num4 = 5;int num4 = 5;fResult = (float)num4/num1;fResult = (float)num4/num1;
1 2 3 4 5
0%
7%
21%
57%
14%
1. 42. 4.03. 54. 0.25. error
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
21 22 23 24 25 26 27 28 29 30
int num3 = 21;int num3 = 21;int num4 = 5;int num4 = 5;int iResult =0;int iResult =0;int iResult = num3%num4;int iResult = num3%num4;
1 2 3 4 5
7%
21%
14%
0%
57%
1. 42. 03. 14. 25. error
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
21 22 23 24 25 26 27 28 29 30
I like this class.I like this class.
14%
86%
1
2
1. Yes2. No
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
21 22 23 24 25 26 27 28 29 30
I am learning UNIXI am learning UNIX
19%
81%
1
2
1. Yes2. No
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
21 22 23 24 25 26 27 28 29 30
I will recommend my I will recommend my friends to take this classfriends to take this class
1 2 3
18%
71%
12%
1. Yes2. No way Jose3. I’m waiting for the
first midterm exam result.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
21 22 23 24 25 26 27 28 29 30
1 2 3 4 5
7%
64%
20%14%14%
String s = “Hello World”;String s = “Hello World”;s.substring(3);s.substring(3);System.out.print(s);System.out.print(s);//what will be printed?//what will be printed?
1. llo World2. lo World3. l4. Hello World
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
21 22 23 24 25 26 27 28 29 30
1 2 3 4
6%13%
6%
75%
String s = “Hello World”;String s = “Hello World”;System.out.print(s.substring(3));System.out.print(s.substring(3));//what will be printed?//what will be printed?
1. llo World2. lo World3. l4. I have no clue.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
21 22 23 24 25 26 27 28 29 30
String s = “Hello World”;String s = “Hello World”;System.out.print(s.substring(0));System.out.print(s.substring(0));//what will be printed?//what will be printed?
1 2 3 4
57%
21%
14%
7%
1. Hello World2. elloWord3. An error will occur4. I don’t want to think
right now.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
21 22 23 24 25 26 27 28 29 30
String s = “Hello World”;String s = “Hello World”;System.out.print(s.length( ));System.out.print(s.length( ));//what will be printed?//what will be printed?
1 2 3 4
20% 20%
7%
53%
1. 102. 113. 124. I’m sleeping…zzzz
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
21 22 23 24 25 26 27 28 29 30
String s = “Hello World”;String s = “Hello World”;System.out.print(s.indexOf(‘a’));System.out.print(s.indexOf(‘a’));//what will be printed?//what will be printed?
1 2 3 4
43%
0%
36%
21%
1. There will be an error
2. 03. -14. 11
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
21 22 23 24 25 26 27 28 29 30
String s = “Hello World”;String s = “Hello World”;System.out.print(s.substring(3,4));System.out.print(s.substring(3,4));//what will be printed?//what will be printed?
1 2 3 4
14%
29%
21%
36%
1. llo World2. lo World3. l4. Please, stop it!!!
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
21 22 23 24 25 26 27 28 29 30
String s = “Hello World”;String s = “Hello World”;System.out.print(s.charAt(0));System.out.print(s.charAt(0));//what will be printed?//what will be printed?
1 2 3 4
88%
6%6%0%
1. H2. d3. l4. There will be an
error
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
21 22 23 24 25 26 27 28 29 30
String s = “Hello World”;String s = “Hello World”;System.out.print(s.charAt(-1));System.out.print(s.charAt(-1));//what will be printed?//what will be printed?
1 2 3 4
0%
60%
33%
7%
1. H2. d3. A blank4. There will be an
error
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
21 22 23 24 25 26 27 28 29 30
An IndexOutOfBoundsException
We import packages (Java We import packages (Java libraries) so that we do not have to libraries) so that we do not have to re-invent the wheel.re-invent the wheel.
25%
75%
1
2
1. True2. False
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
21 22 23 24 25 26 27 28 29 30
When using the DecimalFormat When using the DecimalFormat class, using # and using 0 is the class, using # and using 0 is the samesame
87%
13%
1
2
1. True2. False
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
21 22 23 24 25 26 27 28 29 30
When using the DecimalFormat When using the DecimalFormat we can even add units to the we can even add units to the numbers that we are formattingnumbers that we are formatting
0%
100%
1
2
1. True2. False
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
21 22 23 24 25 26 27 28 29 30
1 2 3
18%12%
71%
Random gen = new Random( );Random gen = new Random( );int num;int num;num = gen.nextInt( );num = gen.nextInt( );
1. Will generate a number between 0 and the highest int number.
2. Will generate a number within the whole int range
3. Will generate a number between 0 and 1
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
21 22 23 24 25 26 27 28 29 30
1 2 3 4 5
14%
36%
21%
14%14%
Random gen = new Random( );Random gen = new Random( );int num;int num;num = gen.nextInt(20);num = gen.nextInt(20);
//will generate a number between://will generate a number between:
1. 0 and 192. 0 and 203. 1 and 194. 1 and 205. Can’t count now.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
21 22 23 24 25 26 27 28 29 30
Java is zero based
1 2 3 4 5
11% 11%
0%
67%
11%
Random gen = new Random( );Random gen = new Random( );int num;int num;num = gen.nextInt(20)+5;num = gen.nextInt(20)+5;
//will generate a number between://will generate a number between:
1. 5 and 252. 4 and 193. 5 and 254. 5 and 245. 4 and 25
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
21 22 23 24 25 26 27 28 29 30
1 2 3 4 5
6%
13%
44%
13%
25%
Are you ready for the Are you ready for the midterm now?midterm now?
1. Yes2. No3. Just a little bit4. Now I know that I don’t
know.5. What midterm?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
21 22 23 24 25 26 27 28 29 30