+ Reply to Thread
Results 1 to 7 of 7
  1. Junior Member Registered Member
    Join Date
    Jul 2012
    Posts
    3
    #1

    Default What is the output of the following code?

    Code:

    public class ExamNameFinder {
    public static String getExamName(String examId) {

    String examName = null;

    if (examId == null) {
    return "ERROR";
    }

    switch (examId) {

    case "1Z0-864": examName = "SCEA 5 Part 1";
    break;

    case "1Z0-804": examName = "OCP Java SE 7";
    break;

    case "1Z0-803": examName = "OCA Java SE 7";
    break;

    default: examName = "ERROR";
    break;
    }

    return examName;
    }


    public static void main(String[] args) {

    String examId = "1Z0-803";
    String examName = ExamNameFinder.getExamName(examId);
    System.out.println(examName);

    }
    }
    Reply With Quote Quote  

  2. SS -->
  3. Senior Member
    Join Date
    Feb 2012
    Posts
    2,426
    #2
    Welcome to TE.

    I noticed your unanswered post so thought I would offer a reply.

    Perhaps if you provided some context including your own thoughts to the problem, there would be more replies. Most forum members will not simply provide an answer to what appears to be a simple homework problem. Myself included.

    Is there some aspect of the case statement that you don't understand?
    Did you already attempt to byte-compile the code and run it through the java intepreter?
    Reply With Quote Quote  

  4. Certification Invigilator Forum Admin JDMurray's Avatar
    Join Date
    Jul 2003
    Location
    Surf City USA
    Posts
    10,600
    Blog Entries
    50

    Certifications
    GSEC, EnCE, CISSP, SSCP, CEH (ANSI), CASP, CCNA, CCENT, CWSP, CWNA, CWTS, Security+, Server+, Network+, A+, DHTI+, PDI+, MSIT InfoSec
    #3
    Once you understand how the switch statement in Java SE 7 works it's a trivial question to answer.

    I hope this isn't an exhibit from a practice exam or dump. ("Moves finger towards big red button...")
    Moderator of the InfoSec, CWNP, IT Jobs, Virtualization, Java, and Microsoft Developers forums at www.techexams.net
    --
    Blog: www.techexams.net/blogs/jdmurray
    LinkedIn: www.linkedin.com/in/jamesdmurray
    Twitter: www.twitter.com/jdmurray
    Reply With Quote Quote  

  5. Junior Member Registered Member
    Join Date
    Jul 2012
    Posts
    3
    #4
    Quote Originally Posted by paul78 View Post
    Welcome to TE.

    I noticed your unanswered post so thought I would offer a reply.

    Perhaps if you provided some context including your own thoughts to the problem, there would be more replies. Most forum members will not simply provide an answer to what appears to be a simple homework problem. Myself included.

    Is there some aspect of the case statement that you don't understand?
    Did you already attempt to byte-compile the code and run it through the java intepreter?
    Thanks for your tips Mr.Paul

    Quote Originally Posted by JDMurray View Post
    Once you understand how the switch statement in Java SE 7 works it's a trivial question to answer.

    I hope this isn't an exhibit from a practice exam or dump. ("Moves finger towards big red button...")
    Thanks Admin
    Last edited by Plantwiz; 08-12-2012 at 10:18 PM. Reason: consecutive posting
    Reply With Quote Quote  

  6. Junior Member Registered Member
    Join Date
    Jul 2012
    Posts
    3
    #5
    Anyway thanks friends, i got the correct solution to my confusion

    here is the solution

    A switch works with the byte, short, char, and int primitive data types. It also works with enumerated, the String class (introduced in Java SE 7), and a few special classes that wrap certain primitive types: Character, Byte, Short, and Integer. The String in the switch expression is compared with the expressions associated with each case label as if the String.equals method were being used.

    So the Correct answer is OCA JAVA SE 7.

    Thanks EPractize Labs Training Lab

    My Friend Suggest me your tool.

    I got the correct answer for my question from your trial version itself. Thanks
    Reply With Quote Quote  

  7. Senior Member
    Join Date
    Feb 2012
    Posts
    2,426
    #6
    Glad you were able to figure it out. Java's dynamic typing can sometimes be a bit confusing if you are used to loosely typed languages.

    Good thing JD didnt have to use his big red button. I think it also launches the space shuttle and sets off all the car alarms within a 2 mile radius.
    Reply With Quote Quote  

  8. Certification Invigilator Forum Admin JDMurray's Avatar
    Join Date
    Jul 2003
    Location
    Surf City USA
    Posts
    10,600
    Blog Entries
    50

    Certifications
    GSEC, EnCE, CISSP, SSCP, CEH (ANSI), CASP, CCNA, CCENT, CWSP, CWNA, CWTS, Security+, Server+, Network+, A+, DHTI+, PDI+, MSIT InfoSec
    #7
    Quote Originally Posted by paul78 View Post
    Good thing JD didnt have to use his big red button. I think it also launches the space shuttle and sets off all the car alarms within a 2 mile radius.
    Nope, that's Webmaster's Big Red Button. Mine mostly causes UPSes to beep menacingly and small dogs to tilt their heads.
    Moderator of the InfoSec, CWNP, IT Jobs, Virtualization, Java, and Microsoft Developers forums at www.techexams.net
    --
    Blog: www.techexams.net/blogs/jdmurray
    LinkedIn: www.linkedin.com/in/jamesdmurray
    Twitter: www.twitter.com/jdmurray
    Reply With Quote Quote  

+ Reply to Thread

Social Networking & Bookmarks