aspose file tools*
The moose likes Mock Exam Errata and the fly likes Q from John Hunt M.E Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Mock Exam Errata
Bookmark "Q from John Hunt M.E " Watch "Q from John Hunt M.E " New topic
Author

Q from John Hunt M.E

Vineet Sharma
Ranch Hand

Joined: Dec 30, 2000
Posts: 51
Hi,
public class Calc{
public static void main(String args[]){

int total = 0;
for(int i =0, j = 10; total>30; ++i, --j){
System.out.println(" i = " + i + " : j = " + j);
total += (i + j);
}
System.out.println("Total " + total);
}
}
Answers:
A. Runtime Error
B. Compiletime Error
C. Prints out "Total = 0"

The correct answer is C. I also ran the prog. and the answer did come out to be C. However, I think it should be B for the following reasons:
1. Type of 'j' has not been declared.
2. In the first part of the for loop (int i = 0, j = 10)is incorrect.
Please Explain
Thanks
Carl Trusiak
Sheriff

Joined: Jun 13, 2000
Posts: 3340
This is an acceptable way(htough can lead to confusion) way to declare multiple variables. It can be done inside the declaration section of a for loop or any where you can declare variables
int i=0, j=5, k=3; //accptable
This brings to lightt another requirement, you can not mix declarations in the declaration of a for loop
//legal
for(int 1 = 0, j = 10;
or
int i = 0;
int j = 0;
for(i = 0, j = 10;
//illegal
int i = 0;
for(i = 0, int j =10;
or
int j = 0;
for(int i =0, j = 10;

Hope this helps


I Hope This Helps
Carl Trusiak, SCJP2, SCWCD
 
wood burning stoves
 
subject: Q from John Hunt M.E