About Question enthuware.ocajp.i.v7.2.1310 :
Moderator: admin
Re: About Question enthuware.ocajp.i.v7.2.1310 :
Forget it. I was looking at my answer, not the correct one.
-
- Site Admin
- Posts: 10053
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocajp.i.v7.2.1310 :
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.
While NetBeans is a great development environment, we don't recommend it to students while preparing for this exam.
HTH,
Paul.
If you like our products and services, please help us by posting your review here.
Re: About Question enthuware.ocajp.i.v7.2.1310 :
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'?
-
- Site Admin
- Posts: 10053
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocajp.i.v7.2.1310 :
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:
HTH,
Paul.
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");
}
}
Paul.
If you like our products and services, please help us by posting your review here.
-
- Posts: 29
- Joined: Wed Apr 17, 2013 9:22 am
- Contact:
Re: About Question enthuware.ocajp.i.v7.2.1310 :
The code in the assignment is indeed valid, everything's fine.
-
- Posts: 6
- Joined: Fri Mar 20, 2015 8:42 am
- Contact:
Re: About Question enthuware.ocajp.i.v7.2.1310 :
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
-
- Posts: 15
- Joined: Sun Jan 28, 2018 12:38 pm
- Contact:
Re: About Question enthuware.ocajp.i.v7.2.1310 :
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 ?
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 ?
-
- Site Admin
- Posts: 10053
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocajp.i.v7.2.1310 :
If you like our products and services, please help us by posting your review here.
Who is online
Users browsing this forum: No registered users and 45 guests