Home  |

HINTS FOR EXAMS

----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

chapters 1 - 4

1. What will be the value of ans after the following code has been executed?

int ans = 10;

int x = 65;

int y = 55;

if (x >= y)

ans = x + y;

ans = __________

2. What will be the value of ans after the following code has been executed?

int x = 90, y = 55, ans = 10;

if ( x == y)

ans *= 2;

ans = _________________

3.       What will the ltr and strSize  be as a  result of executing the following code?

int x = 12;

String msg = "I love the Spring.";

char ltr = msg.charAt(x);

int strSize = msg.length();

System.out.println("Character at index x = " +

ltr);

System.out.println("msg has " + strSize +

" characters.");

ltr  will  = __________

strSize will = ____________

4.    What will be the values of   ans,  x,  and y  after the following statements are executed?

int ans = 35, x = 50, y =50;

if ( x < y)

{

ans = x + 10;

x -=y;

}

else

{

ans = y + 20;

y += x;

}

ans =  _____________________

x =  ________________________

y =  __________________________

5.      What will be the value of    bonus   after the following code is executed?

int bonus, sales = 7500;

if       (sales < 5000)

bonus = 200;

else if         (sales < 7500)

bonus = 500;

else  if (sales < 10000)

bonus = 750;

else if (sales < 20000)

bonus = 1000;

else

bonus = 1250;

bonus  =  ___________________________

6.                What would be the value of   bonus  after the following statements are executed?

int bonus, sales = 1250;

if (sales > 1000)

bonus = 100;

if (sales > 750)

bonus = 50;

if (sales > 500)

bonus = 25;

else

bonus = 0;

bonus   =  ________________________________

7.      What would be the value of    bonus   after the following statements are executed?

int bonus, sales = 75000;

char dept = 'S';

if   (sales > 100000)

if (dept == 'R')

bonus = 2000;

else

bonus = 1500;

else  if (sales > 65000)

if (dept == 'S')

bonus = 1250;

else

bonus = 1000;

else

bonus = 0;

bonus   =    ______________________

8. What will be the values of   ans,  x,  and  y  after the following statements are executed?

int ans = 0, x = 15, y =25;

if ( x >= y)

{

ans = x + 10;

x -=y;

}

else

{

ans = y + 10;

y += x;

}

ans =  _____________________

x =  ________________________

y =  __________________________

9.       What would be the value of   discountRate   after the following statements are executed?

double discountRate = .02;

int purchase = 100;

if (purchase > 1000)

discountRate = .05;

else if (purchase > 750)

discountRate = .03;

else if (purchase > 500)

discountRate = .01;

discountRate    =    _______________________

10.     What would be the value of   discountRate   after the following statements are executed?

double discountRate = 0.0;

int purchase = 1000;

if (purchase > 950)

discountRate = .05;

if (purchase > 750)

discountRate = .04;

if (purchase > 500)

discountRate = .03;

else

discountRate = .02;

discountRate    =    _______________________

11.    What would be the value of     discountRate    after the following statements are executed?

double discountRate = 0.0;

int purchase = 1250;

char cust = 'N';

if (purchase > 1000)

if (cust == 'Y')

discountRate = .05;

else

discountRate = .04;

else if (purchase > 750)

if (cust == 'Y')

discountRate = .03;

else

discountRate = .02;

else

discountRate = 0;

discountRate    =    _______________________

12.     What would be the value of     discountRate    after the following statements are executed?

double discountRate;

char custType = 'B';

switch (custType)

{

case 'A':

discountRate = .08;

case 'B':

discountRate = .06;

case 'C':

discountRate = .04;

break;

default:

discountRate = 0.0;

}

discountRate    =    _______________________

13.        What will be the value of x after the following code is executed?

int x = 10;

do

{

x *= 20;

}

while (x < 5);

x   =   _________________________

14.    What will be the value of x after the following code is executed?

int x = 10, y = 20;

while (y < 100)

{

x += y;

y += 20;

}

x   =   _________________________

15.        How many times will the following do-while loop be executed?

int x = 11;

do

{

x += 20;

}

while (x <= 100);

________________________     times

16.        What will be the value of x after the following code is executed?

int x = 10;

while (x < 100)

{

x += 10;

}

x   =   _________________________

17.    How many times will the following do-while loop be executed?

int x = 11;

do

{

x += 20;

} while (x > 100);

________________________     times

18.     How many times will the following for loop be executed?

for (int count = 10; count < 25; count++)

System.out.println("Hello World!!!");

_____________________ times

19.       What will be the value of x after the following code is executed?

int x = 10;

for (int y = 5; y < 20; y +=5)

x += y;

x = _________________________________________

[Complete the HINTS,  THEN transfer your  answers to the sheet

and email ONLY THE ANSWER SHEET [as well as the previous discussion questions] to Dr. Guynes]

1.         ans = _____

2.         ans =_____

3.         ltr = __________     StrSize = ______

4              ans = _____  x = _____       y = _____

5.         bonus = _____

6.         bonus =______

7.         bonus = _____

8.         ans = _____  x = _____       y = _____

9.         discountRate = _____

10.      discountRate = _____

11.      discountRate = _____

12.      discountRate = _____

13.      x = _____

14.      x =  _____

15.      executed  _______ times

16.      x = ____

17.      executed _______ times

18.      executed _______ times

19.      x = _____

more from chapter 5 - 7

1. What will be the value of a after the following code is executed?

int [  ] x = {22, 33, 44};

arrayProcess(x);

public static void arrayProcess(int [  ] a)

{

for(int k = 0; k < 3; k++)

{

a  [k] = a [k] + 7;

}

}

a  =  _________________

2.      What will be returned from the following  ‘numr’ method?

public static double numr()

{

double a = 8.5 + 6.5;

return a;

}

_____  will be returned

3.           For the following code, what would be the value of str ?

String [ ] str = {"abc", "def", "ghi", "jkl"};

value will be    ____________

4.      What would be the range of subscript values that could be used with hours [ ]?

final int EMPLOYEES = 15;

int [ ] hours =  new int [EMPLOYEES];

the range will be ________     to __________________

5.  What will be the value of x  after the following code has been executed?

final int SUB = 12;

int [  ] x = new int [SUB];

int  y = 100;

for (int i = 0; i < SUB; i++)

{

x [ i ] = y;

y += 10;

}

x   =  __________

A

1.   a  =  _________________

2.   _____  will be returned

3.   value will be    ____________

4.    the range will be ________     to __________________

5.   x   =  __________