About Question enthuware.ocajp.i.v7.2.1119 :

All the posts and topics that contain only an error report will be moved here after the error is corrected. This is to ensure that when users view a question in ETS Viewer, the "Discuss" button will not indicate the presence of a discussion that adds no value to the question.

Moderators: Site Manager, fjwalraven

Post Reply
ETS User

About Question enthuware.ocajp.i.v7.2.1119 :

Post by ETS User »

Easy test, question 36.

The answer within the enthuware application is wrong. See code below:

Code: Select all

public class Switcher{ 
   public static void main(String[] args){
       switch(Integer.parseInt(args[1]))  //1{
          case 0 :
             boolean b = false;
             break;     
          case 1 :
             b = true; //2
             break;
       }
       if(b) System.out.println(args[2]);
   }
}
What will the above program print if run using the following command line: java Switcher 1 2 3

The program cannot be compiled, therefore it cannot be run. It doesn't matter how the question is worded, the code simply does not compile and it would be wrong to ask someone learning Java to temporarily suspend this and postulate on what might otherwise happen.

The correct answer is "It will not compile because of //1."

Code: Select all

[brrees@mnlowdk03273 ~]$ javac Switcher.java 
Switcher.java:4: error: '{' expected
       switch(Integer.parseInt(args[1]))  //1{
                                        ^
1 error
Your system tells me "There is no problem here because Integer.parseInt() returns an int."
Sure, while that statement is indeed correct, the "// 1 {" is not correct and causes a compilation error.

Please correct.

admin
Site Admin
Posts: 10066
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

Re: About Question enthuware.ocajp.i.v7.2.1119 :

Post by admin »

You are right. Formatting on that line has caused { to be displayed on the same line as //1. This has now been fixed. Other than that the answer is fine.

thank you for your feedback!
If you like our products and services, please help us by posting your review here.

Guest

Re: About Question enthuware.ocajp.i.v7.2.1119 :

Post by Guest »

: ) Thanks kindly

Much appreciated.

Hope I didn't sound rude, I was just somewhat baffled.

Cheers.

Post Reply

Who is online

Users browsing this forum: No registered users and 123 guests