Title: Midterm II
1Midterm II
2Two Classes used to read user input
- Scanner
- BufferedReader
- StringReader
- 1 and 2
- 1 and 3
3The BufferedReader may throw the following
exception
- InputMismatchException
- StringOutOfBoundsException
- NumberFormatException
- IndexOutOfBoundsException
- None
4The Scanner may throw the following exception
- InputMismatchException
- StringOutOfBoundsException
- NumberFormatException
- IndexOutOfBoundsException
- None
5Integer.parseInt throws the following exception
- InputMismatchException
- StringOutOfBoundsException
- NumberFormatException
- IndexOutOfBoundsException
- None
6String s JAVAint x s.charAt(-1)returns
This slide changed to fix a typo
- InputMismatchException
- IndexOutOfBoundsException
- NumberFormatException
- Nothing, it is blank
- None of the above
7String s JAVAint x s.charAt(2)returns
- InputMismatchException
- A
- V
- StringOutOfBoundsException
- Nothing, it is blank
- None of the above
8if(ilt20igt25)
- True for all numbers between 20 and 25
- True for all numbers between 21 and 24
- True for all numbers less than 20 and greater
than 25 - Never true
9if(ilt20igt25)
- True for all numbers between 20 and 25
- True for all numbers between 21 and 24
- True for all numbers less than 20 and greater
than 25 - Never True
10if(igt20ilt25)
- True for all numbers less than 20 and greater
than 25 - True for all numbers between 21 and 24
- True for all numbers
- Never true
11if(igt20ilt25)
- True for all numbers less than 20 and greater
than 25 - True for all numbers between 21 and 24
- True for all numbers
- Never true
12How many times will the loop execute?for(i0
ilt5 ii2)
- Will never execute
- Will execute 2 times
- Will execute 3 times
- Will execute 4 times
- Infinite Loop
13How many times will the loop execute?for(i0
igt5 ii2)
- Will never execute
- Will execute 2 times
- Will execute 3 times
- Will execute 4 times
- Infinite Loop
14How many times will the loop execute?for(i0
igt5 ii-1)
- Will never execute
- Will execute 2 times
- Will execute 3 times
- Will execute 4 times
- Infinite Loop
15How many times will the loop execute?int x
2while(xlt5) xx(x2)
- Will never execute
- Will execute 2 times
- Will execute 3 times
- Will execute 4 times
- Infinite Loop
16How many times will the loop execute?int x
3while(xlt5) xx(x2)
- Will never execute
- Will execute 2 times
- Will execute 3 times
- Will execute 4 times
- Infinite Loop
17How many times will the loop execute?int x
18while(xgt5) xx-(x/3)
- Will never execute
- Will execute 2 times
- Will execute 3 times
- Will execute 4 times
- Infinite Loop
18Switch statements work with
- int
- char
- String
- doolean
- Any primitive data type
- Only 1 and 2
- Only 1,2 and 3
19switch(x) case 1 case 2 case 3 xx1
case 4 xx2 default xx-5
Runing this code with x 2, After executing the
switch statement What will be the value of x?
- 2
- 3
- 4
- 5
- 0
20switch(x) case 1 xx1
break case 2 xx2 break
case 3 xx1 break default
xx-5
Runing this code with x 7, After executing the
switch statement What will be the value of x?
- 2
- 3
- 4
- 5
- 0
21switch(x) case 1 xx1 case 2 xx2
break case 3 xx1 default
xx-5
Runing this code with x 2, After executing the
switch statement What will be the value of x?
- 2
- 3
- 4
- 5
- 0
22switch(x) case 1 xx1 case 2 xx2
break case 3 xx1 default
xx-5
Runing this code with x 1, After executing the
switch statement What will be the value of x?
- 2
- 3
- 4
- 5
- 0
23String s1JAVAString s2javAboolean
areEqualfalseareEqual s1.equals(s2)
areEqual is
- True
- False