Download Midterm II Review

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

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

Document related concepts
no text concepts found
Transcript
Midterm II
ICS111
Two Classes used to
read user input
1.
2.
3.
4.
5.
Scanner
BufferedReader
StringReader
1 and 2
1 and 3
The BufferedReader may
throw the following exception
1.
2.
3.
4.
5.
InputMismatchException
StringOutOfBoundsException
NumberFormatException
IndexOutOfBoundsException
None
The Scanner may throw the
following exception
1.
2.
3.
4.
5.
InputMismatchException
StringOutOfBoundsException
NumberFormatException
IndexOutOfBoundsException
None
Integer.parseInt
throws the following exception
1.
2.
3.
4.
5.
InputMismatchException
StringOutOfBoundsException
NumberFormatException
IndexOutOfBoundsException
None
String s = “JAVA”;
int x = s.charAt(-1);
returns
This slide
changed to fix
a typo
1.
2.
3.
4.
5.
InputMismatchException
IndexOutOfBoundsException
NumberFormatException
Nothing, it is blank
None of the above
String s = “JAVA”;
int x = s.charAt(2);
returns
1.
2.
3.
4.
5.
6.
InputMismatchException
A
V
StringOutOfBoundsException
Nothing, it is blank
None of the above
if(i<20||i>25)
1. True for all numbers
between 20 and 25
2. True for all numbers
between 21 and 24
3. True for all numbers
less than 20 and
greater than 25
4. Never true
if(i<20&&i>25)
1. True for all numbers
between 20 and 25
2. True for all numbers
between 21 and 24
3. True for all numbers
less than 20 and
greater than 25
4. Never True
if(i>20||i<25)
1. True for all numbers
less than 20 and
greater than 25
2. True for all numbers
between 21 and 24
3. True for all numbers
4. Never true
if(i>20&&i<25)
1. True for all numbers
less than 20 and
greater than 25
2. True for all numbers
between 21 and 24
3. True for all numbers
4. Never true
How many times will the loop
execute?
for(i=0; i<5; i=i+2){
1.
2.
3.
4.
5.
Will never execute
Will execute 2 times
Will execute 3 times
Will execute 4 times
Infinite Loop
How many times will the loop
execute?
for(i=0; i>5; i=i+2){
1.
2.
3.
4.
5.
Will never execute
Will execute 2 times
Will execute 3 times
Will execute 4 times
Infinite Loop
How many times will the loop
execute?
for(i=0; i>5; i=i-1){
1.
2.
3.
4.
5.
Will never execute
Will execute 2 times
Will execute 3 times
Will execute 4 times
Infinite Loop
How many times will the loop execute?
int x = 2;
while(x<5){
x=x+(x%2);
}
1.
2.
3.
4.
5.
Will never execute
Will execute 2 times
Will execute 3 times
Will execute 4 times
Infinite Loop
How many times will the loop execute?
int x = 3;
while(x<5){
x=x+(x%2);
}
1.
2.
3.
4.
5.
Will never execute
Will execute 2 times
Will execute 3 times
Will execute 4 times
Infinite Loop
How many times will the loop execute?
int x = 18;
while(x>5){
x=x-(x/3);
}
1.
2.
3.
4.
5.
Will never execute
Will execute 2 times
Will execute 3 times
Will execute 4 times
Infinite Loop
Switch statements work with
1.
2.
3.
4.
5.
int
char
String
doolean
Any primitive data
type
6. Only 1 and 2
7. Only 1,2 and 3
Runing this code
with x = 2,
After executing
the switch
statement
What will be the
value of x?
1.
2.
3.
4.
5.
2
3
4
5
0
switch(x){
case 1:
case 2:
case 3: x=x+1;
case 4: x=x+2;
default: x=x-5;
}
Runing this code
with x = 7,
After executing
the switch
statement
What will be the
value of x?
1.
2.
3.
4.
5.
2
3
4
5
0
switch(x){
case 1: x=x+1;
break;
case 2: x=x+2;
break
case 3: x=x+1;
break;
default: x=x-5;
}
Runing this code
with x = 2,
After executing
the switch
statement
What will be the
value of x?
1.
2.
3.
4.
5.
2
3
4
5
0
switch(x){
case 1: x=x+1;
case 2: x=x+2;
break
case 3: x=x+1;
default: x=x-5;
}
Runing this code
with x = 1,
After executing
the switch
statement
What will be the
value of x?
1.
2.
3.
4.
5.
2
3
4
5
0
switch(x){
case 1: x=x+1;
case 2: x=x+2;
break
case 3: x=x+1;
default: x=x-5;
}
String s1=“JAVA”;
String s2=“javA”;
boolean areEqual=false;
areEqual =s1.equals(s2);
areEqual is:
1. True
2. False
Related documents