Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.programmer > #36190 > unrolled thread
| Started by | Yesi Gebre <yesi.gebreselassie@gmail.com> |
|---|---|
| First post | 2017-01-13 19:16 -0800 |
| Last post | 2017-02-12 11:06 -0800 |
| Articles | 6 — 4 participants |
Back to article view | Back to comp.lang.java.programmer
I am unable to run my Bluej Code Yesi Gebre <yesi.gebreselassie@gmail.com> - 2017-01-13 19:16 -0800
Re: I am unable to run my Bluej Code Andreas Leitgeb <avl@logic.at> - 2017-01-14 09:15 +0000
Re: I am unable to run my Bluej Code lewbloch@gmail.com - 2017-01-14 11:36 -0800
Re: I am unable to run my Bluej Code Andreas Leitgeb <avl@logic.at> - 2017-01-14 20:23 +0000
Re: I am unable to run my Bluej Code Arne Vajhøj <arne@vajhoej.dk> - 2017-01-14 19:49 -0500
Re: I am unable to run my Bluej Code lewbloch@gmail.com - 2017-02-12 11:06 -0800
| From | Yesi Gebre <yesi.gebreselassie@gmail.com> |
|---|---|
| Date | 2017-01-13 19:16 -0800 |
| Subject | I am unable to run my Bluej Code |
| Message-ID | <7bbab5d9-5eca-406b-bd0d-bb7caa28525a@googlegroups.com> |
class ChkNum{
//return true if x is even
boolean isEven(int x){
if((x % 2) == 0) return true;
else return false;
}
}
class ParmDemo{
public static void main(String args[]){
ChkNum e = new ChkNum();
if(e.isEven(10)) System.out.println("10 is even. ");
if(e.isEven(9)) System.out.println("9 is even. ");
if(e.isEven(8)) System.out.println("8 is even. ");
}
}
I cannot run this program in Bluej . When I go to run it void main string isn't there as one of the options. Please Help
[toc] | [next] | [standalone]
| From | Andreas Leitgeb <avl@logic.at> |
|---|---|
| Date | 2017-01-14 09:15 +0000 |
| Message-ID | <slrno7jr19.pvm.avl@logic.at> |
| In reply to | #36190 |
Yesi Gebre <yesi.gebreselassie@gmail.com> wrote:
> class ChkNum{
> //return true if x is even
> boolean isEven(int x){
> if((x % 2) == 0) return true;
> else return false;
> }
> }
This is a NO-GO! You make it look like this was end of
isEven, but it is already end of class ChkNum. please
align all close braces with the column at which the line
with the matching open brace starts!
Maybe you even confused yourself into thinking that ParmDemo
was "inside" ChkNum.
> class ParmDemo{
If the source file containing your code is called ParmDemo.java,
then you can make this class public, and then it might show up as
a possible starting class.
If the file is ChkNum.java or something completely different,
(which for non-public classes is possible), then rename it to
ParmDemo.java, first, and still make the class ParmDemo public.
> public static void main(String args[]){
> ChkNum e = new ChkNum();
> if(e.isEven(10)) System.out.println("10 is even. ");
> if(e.isEven(9)) System.out.println("9 is even. ");
> if(e.isEven(8)) System.out.println("8 is even. ");
> }
>
> }
>
>
> I cannot run this program in Bluej . When I go to run it void main string isn't there as one of the options. Please Help
[toc] | [prev] | [next] | [standalone]
| From | lewbloch@gmail.com |
|---|---|
| Date | 2017-01-14 11:36 -0800 |
| Message-ID | <c95dbb71-a5e4-4752-99b1-4772bced1c3c@googlegroups.com> |
| In reply to | #36190 |
On Friday, January 13, 2017 at 7:16:32 PM UTC-8, Yesi Gebre wrote:
> class ChkNum{
> //return true if x is even
> boolean isEven(int x){
> if((x % 2) == 0) return true;
> else return false;
> }
> }
`(x % 2) == 0` is already a boolean expression, so making it a conditional to turn it into a boolean is rather gilding the lily, wouldn't you say?
--
Lew
[toc] | [prev] | [next] | [standalone]
| From | Andreas Leitgeb <avl@logic.at> |
|---|---|
| Date | 2017-01-14 20:23 +0000 |
| Message-ID | <slrno7l268.pvm.avl@logic.at> |
| In reply to | #36192 |
lewbloch@gmail.com <lewbloch@gmail.com> wrote:
> On Friday, January 13, 2017 at 7:16:32 PM UTC-8, Yesi Gebre wrote:
>> class ChkNum{
>> //return true if x is even
>> boolean isEven(int x){
>> if((x % 2) == 0) return true;
>> else return false;
>> }
>> }
> `(x % 2) == 0` is already a boolean expression, so making it
> a conditional to turn it into a boolean is rather gilding the
> lily, wouldn't you say?
I wouldn't say. OP's way makes it easier to add logging code
lateron.
Even better would be, if the statements were even "embraced".
[toc] | [prev] | [next] | [standalone]
| From | Arne Vajhøj <arne@vajhoej.dk> |
|---|---|
| Date | 2017-01-14 19:49 -0500 |
| Message-ID | <o5egvk$1tmr$1@gioia.aioe.org> |
| In reply to | #36193 |
On 1/14/2017 3:23 PM, Andreas Leitgeb wrote:
> lewbloch@gmail.com <lewbloch@gmail.com> wrote:
>> On Friday, January 13, 2017 at 7:16:32 PM UTC-8, Yesi Gebre wrote:
>>> class ChkNum{
>>> //return true if x is even
>>> boolean isEven(int x){
>>> if((x % 2) == 0) return true;
>>> else return false;
>>> }
>>> }
>> `(x % 2) == 0` is already a boolean expression, so making it
>> a conditional to turn it into a boolean is rather gilding the
>> lily, wouldn't you say?
>
> I wouldn't say. OP's way makes it easier to add logging code
> lateron.
> Even better would be, if the statements were even "embraced".
What is wrong with:
boolean isEven(int x) {
boolean res = ((x % 2) == 0);
if(log.isDebugEnabled()) {
log.debug(x + isEven: " + res);
}
return res;
}
Arne
[toc] | [prev] | [next] | [standalone]
| From | lewbloch@gmail.com |
|---|---|
| Date | 2017-02-12 11:06 -0800 |
| Message-ID | <8bb6b60a-31c6-46c6-ab7b-8e73430f1021@googlegroups.com> |
| In reply to | #36193 |
Andreas Leitgeb wrote:
> lewbloch wrote:
> > On Friday, January 13, 2017 at 7:16:32 PM UTC-8, Yesi Gebre wrote:
> >> class ChkNum{
> >> //return true if x is even
> >> boolean isEven(int x){
> >> if((x % 2) == 0) return true;
> >> else return false;
> >> }
> >> }
> > `(x % 2) == 0` is already a boolean expression, so making it
> > a conditional to turn it into a boolean is rather gilding the
> > lily, wouldn't you say?
>
> I wouldn't say. OP's way makes it easier to add logging code
> lateron.
> Even better would be, if the statements were even "embraced".
If you want to add logging "later on", first of all, why didn't you "add" logging in the first place?
And it's even clearer if you must preserve the return value, to assign it to a variable. This ugly `if (c) then {return true;} else {return false;]` business is unnecessary. Just use something like
final boolean is = evaluateCondition();
// Do whatever you need to here, but don't defer logging until "later"
return is;
--
Lew
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.java.programmer
csiph-web