Page 1 of 1

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

Posted: Tue Jul 31, 2012 8:36 pm
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.

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

Posted: Tue Jul 31, 2012 10:45 pm
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!

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

Posted: Wed Aug 01, 2012 3:06 am
by Guest
: ) Thanks kindly

Much appreciated.

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

Cheers.