23
Midterm II ICS111

Midterm II ICS111. Two Classes used to read user input 1.Scanner 2.BufferedReader 3.StringReader 4.1 and 2 5.1 and 3

  • View
    213

  • Download
    0

Embed Size (px)

Citation preview

Midterm II

ICS111

Two Classes used to read user input

1. Scanner

2. BufferedReader

3. StringReader

4. 1 and 2

5. 1 and 3

The BufferedReader may throw the following exception

1. InputMismatchException

2. StringOutOfBoundsException

3. NumberFormatException

4. IndexOutOfBoundsException

5. None

The Scanner may throw the following exception

1. InputMismatchException

2. StringOutOfBoundsException

3. NumberFormatException

4. IndexOutOfBoundsException

5. None

Integer.parseInt throws the following exception

1. InputMismatchException

2. StringOutOfBoundsException

3. NumberFormatException

4. IndexOutOfBoundsException

5. None

String s = “JAVA”;int x = s.charAt(-1);

returns

1. InputMismatchException

2. IndexOutOfBoundsException

3. NumberFormatException

4. Nothing, it is blank

5. None of the above

This slide changed to fix a typo

String s = “JAVA”;int x = s.charAt(2);

returns

1. InputMismatchException

2. A

3. V

4. StringOutOfBoundsException

5. Nothing, it is blank

6. 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. Will never execute

2. Will execute 2 times

3. Will execute 3 times

4. Will execute 4 times

5. Infinite Loop

How many times will the loop execute?for(i=0; i>5; i=i+2){

1. Will never execute

2. Will execute 2 times

3. Will execute 3 times

4. Will execute 4 times

5. Infinite Loop

How many times will the loop execute?for(i=0; i>5; i=i-1){

1. Will never execute

2. Will execute 2 times

3. Will execute 3 times

4. Will execute 4 times

5. Infinite Loop

How many times will the loop execute?int x = 2;while(x<5){ x=x+(x%2);}

1. Will never execute

2. Will execute 2 times

3. Will execute 3 times

4. Will execute 4 times

5. Infinite Loop

How many times will the loop execute?int x = 3;while(x<5){ x=x+(x%2);}

1. Will never execute

2. Will execute 2 times

3. Will execute 3 times

4. Will execute 4 times

5. Infinite Loop

How many times will the loop execute?int x = 18;while(x>5){ x=x-(x/3);}

1. Will never execute

2. Will execute 2 times

3. Will execute 3 times

4. Will execute 4 times

5. Infinite Loop

Switch statements work with1. int

2. char

3. String

4. doolean

5. Any primitive data type

6. Only 1 and 2

7. Only 1,2 and 3

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 = 2, After executing the switch statementWhat will be the value of x?

1. 2

2. 3

3. 4

4. 5

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 = 7, After executing the switch statementWhat will be the value of x?

1. 2

2. 3

3. 4

4. 5

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 = 2, After executing the switch statementWhat will be the value of x?

1. 2

2. 3

3. 4

4. 5

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 statementWhat will be the value of x?

1. 2

2. 3

3. 4

4. 5

5. 0

String s1=“JAVA”;String s2=“javA”;boolean areEqual=false;areEqual =s1.equals(s2);

areEqual is:

1. True

2. False