Download presentation
Presentation is loading. Please wait.
1
Midterm II ICS111
2
Two Classes used to read user input 1.Scanner 2.BufferedReader 3.StringReader 4.1 and 2 5.1 and 3
3
The BufferedReader may throw the following exception 1.InputMismatchException 2.StringOutOfBoundsException 3.NumberFormatException 4.IndexOutOfBoundsException 5.None
4
The Scanner may throw the following exception 1.InputMismatchException 2.StringOutOfBoundsException 3.NumberFormatException 4.IndexOutOfBoundsException 5.None
5
Integer.parseInt throws the following exception 1.InputMismatchException 2.StringOutOfBoundsException 3.NumberFormatException 4.IndexOutOfBoundsException 5.None
6
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
7
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
8
if(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
9
if(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
10
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
11
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
12
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
13
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
14
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
15
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
16
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
17
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
18
Switch statements work with 1.int 2.char 3.String 4.doolean 5.Any primitive data type 6.Only 1 and 2 7.Only 1,2 and 3
19
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 statement What will be the value of x? 1.2 2.3 3.4 4.5 5.0
20
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 statement What will be the value of x? 1.2 2.3 3.4 4.5 5.0
21
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 statement What will be the value of x? 1.2 2.3 3.4 4.5 5.0
22
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 2.3 3.4 4.5 5.0
23
String s1=“JAVA”; String s2=“javA”; boolean areEqual=false; areEqual =s1.equals(s2); areEqual is: 1.True 2.False
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.