Page 1 of 1

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

Posted: Thu Jul 12, 2012 5:05 pm
by ETS User
Why will it not compile?

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

Posted: Thu Jul 12, 2012 9:49 pm
by Guest
Forget it. I was looking at my answer, not the correct one.

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

Posted: Mon Oct 29, 2012 9:47 am
by Guest
This example chokes on NetBeans 7.3 beta

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

Posted: Mon Oct 29, 2012 12:29 pm
by admin
Not sure what you mean by "choke". It compiles and runs fine on notepad + command line.

While NetBeans is a great development environment, we don't recommend it to students while preparing for this exam.

HTH,
Paul.

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

Posted: Sun Dec 09, 2012 3:38 am
by BEW
If I use a command line or if I use TextEdit it compiles but it doesn't print anything. Even If I supply the value of false in the command line it doesn't print anything for me. I created a class name, installed a main method and played with the ifTest method by removing void and inserting boolean but it never prints anything. I supplied the value of false for flag and created a return statement when I removed void from the ifTest method but it won't print anything. What should be the proper command line entry on a Mac to make this work? What else needs to happen to the code in the question (not the explanation) to make this print 'False False'?

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

Posted: Sun Dec 09, 2012 8:00 am
by admin
BEW, If you post your code, I can try to see why it doesn't print anything. But try to compile and run the following code:

Code: Select all

public class TestClass{

   public static void  main(String[] args){
      ifTest(false);
  }

 public static void ifTest(boolean flag){
   if (flag)   //1
   if (flag)   //2
   if (flag)   //3
   System.out.println("False True");
   else        //4
   System.out.println("True False");
   else        //5
   System.out.println("True True");
   else        //6
   System.out.println("False False");
 }

}
HTH,
Paul.

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

Posted: Thu Apr 18, 2013 5:43 am
by insider
The code in the assignment is indeed valid, everything's fine.

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

Posted: Fri Mar 27, 2015 4:59 am
by davidkkkk
To save time, when all the "if" tests are the same and the pattern is the same as the given, the output can only be the first one or the last one. You can add 10 more "if" it will be the same ;)

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

Posted: Thu Feb 15, 2018 10:10 am
by ArpRokz
Why is this compiling successfully ?

The program can never print True True or True False, this should lead to an unreachable code error .. isn't it ?

Can anyone explain to me when to look for the unreachable code error ?

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

Posted: Thu Feb 15, 2018 11:51 am
by admin