1 Replies - 596 Views - Last Post: 22 February 2008 - 10:14 AM Rate Topic: -----

#1 soccerizzy26  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 69
  • Joined: 23-January 08

Solving Problems without compiler

Posted 22 February 2008 - 07:24 AM

For an assignment I was given 9 problems to solve without using a compiler just solving them mentally. When I gave back my answers he said 3 were wrong and if I correct them I will still recieve credit so I'm going to show the work I've done since then and I guess I'm hoping for advice if I'm going in the right direction or not.

1.This fragment:
if (alpha >= beta)
charlie = delta;
else
epsilon = foxtrot;


is equivalent to which of the following?

A
if (alpha >= beta);
charlie = delta;
if (alpha < beta);
epsilon = foxtrot;


B
if (beta < alpha)
charlie = delta;
else
epsilon = foxtrot;


C
if (beta >= alpha)
charlie = delta;
else
epsilon = foxtrot; 



D
if (beta <= alpha)
charlie = delta;
else if (beta > alpha)
epsilon = foxtrot;



When I looked over the problem again I got answer D because it still basically says if alpha is greater than or equal to beta then charlie = delta and if beta is greater than alpha then epsilon = foxtrot


2.
What is printed?

int result = 2;
int cnt = 5;
for (cnt = 0; cnt < 5; cnt++);
result += cnt;
System.out.println("result = " + result);

A. result = 17
B. result = 5
C. result = 12
D. result = 7

the first time I took this quiz I put C now that I'm looking at it I got A becuase metally if cnt=0 and cnt is less than 5 and cnt ++ then written out wouldn't the equation look a little like this. (5+4+3+2+1)=15 then result+= cnt will be
result= 15+2 so therefore result = 17 would be the answer.

3.
What is the value of the int variable d after the following statement is executed?

for (d = 1; d < 567; d *= 10);

A. 1
B. 10
C. 1000
D. 100


For this problem I was utterly confused and took a blind stab at it on the quiz, now that I have the time to look at it, the problem seems very simple. Wouldn't the answer be B. because since d = 1 and d* = 10 then wouldn't I multiply 1 by 10 or 1 * 10 and the answer would be 10?

Is This A Good Question/Topic? 0
  • +

Replies To: Solving Problems without compiler

#2 letthecolorsrumble  Icon User is offline

  • Student of The Sun
  • member icon

Reputation: 27
  • View blog
  • Posts: 555
  • Joined: 07-November 07

Re: Solving Problems without compiler

Posted 22 February 2008 - 10:14 AM

d*=10 a.k.a d = d * 10.

For the second one, if you look properly; you will see a ; after for-loop. That is enough help for you :)

This post has been edited by letthecolorsrumble: 22 February 2008 - 10:14 AM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1