• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

New to java

 
jodi clark
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey all,

im very new to java and have no idea why the following code wont work. Any suggestions would be muchly appreciated =0)

[ edited to preserve formatting using the [code] and [/code] UBB tags -ds ]
[ July 13, 2004: Message edited by: Dirk Schreckmann ]
 
Anonymous
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
One of the faults in the programm is

should be

= : is an assignment operation
== : is comparison

bye
 
jodi clark
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks for your reply....the following is the error msg i get


Process completed.

[ edited to preserve formatting using the [code] and [/code] UBB tags -ds ]
[ July 13, 2004: Message edited by: Dirk Schreckmann ]
 
Davy Kelly
Ranch Hand
Posts: 384
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
your main method has not got an open { is this meant, or did you just forget it in this post?

if you are getting this message, num=((num%2)=true); you are assigning num which is int to a boolean, this is not allowed.

maybe this is what you wanted to try:
num1=((num % 2)==0); //note the double ==
if(num1)
{
System.out.println(num + " is a prime number.");
}

Davy

[ July 13, 2004: Message edited by: Davy Kelly ]
[ July 13, 2004: Message edited by: Davy Kelly ]
 
jodi clark
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
:roll:

ummm which one, where? did i happen to mention i was clueless?
 
Davy Kelly
Ranch Hand
Posts: 384
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
forgive my statement about the {, i see what I missed now, not done java in 4 months, and trying to get back into it.

I see you throws the io exception then you opened it....

Davy
[ July 13, 2004: Message edited by: Davy Kelly ]
 
jodi clark
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ugh...totally missed that.
Thanks
 
jodi clark
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
=0) thanks

{

this code now gives me the following error, did i delete something i shouldn't have?

[ edited to preserve formatting using the [code] and [/code] UBB tags -ds ]
[ July 13, 2004: Message edited by: Dirk Schreckmann ]
 
Uwe Suelter
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Jodi,

in your code you wrote:

public static void main(String[] args)
throws java.io.IOException;

you should remove the semikolon ; behind the IOException,
that should solve your problem

Regards
Uwe
 
jodi clark
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Uwe....

ok so this is what i have now....6 hours in to it
i cant end my loops...they're infinite...just keep going and going and going.
how does one stop the darn things?

 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24208
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, nothing in the "while" loop changes the value of "num", but the while's condition is waiting for num to become 0. Do you mean to assign a new value to "num" somewhere inside the while loop?
 
jodi clark
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i understand what ur saying....but i think my brain has farted :roll: and im now totally clueless on what to do? Could you give me a further hint?
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry to join late ... that problem using = instead of == is very common. It gave me fits coming from other languages that used = in both places. (I appreciate smart compilers!) I picked up a habit of putting literals on the left

if ( null == myObj )
if ( 0 == myInt )
if ( "".equals(myString) ) // Never get null pointer exception!

Now if I accidentally type = instead of == I'll get a compiler error. I might have to stare at it for a while to see it, but that's better than a really strange runtime error for sure.
[ July 13, 2004: Message edited by: Stan James ]
 
Darin Niard
Ranch Hand
Posts: 118
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Just some quick comments...

  • You have an extra set of brackets surrounding your while loop.
  • When dealing with booleans if (num1==true) is not necessary. if (num1) is sufficient.
  • Putting continue at the end of a loop is redundant (both of yours are in this case).
  • Like someone else said, whatever is in control of your loop has to be altered within the loop in order for it to ever reach an ending. Your num is never 0, so num!=0 will always pass the test.


  • [ July 13, 2004: Message edited by: Darin Niard ]
     
    jodi clark
    Greenhorn
    Posts: 10
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    thank you all for ur assistance
     
    Davy Kelly
    Ranch Hand
    Posts: 384
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    have you got it working the way you want it?

    Davy
     
    jodi clark
    Greenhorn
    Posts: 10
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Yes tyvm, it is =0)
     
    • Post Reply
    • Bookmark Topic Watch Topic
    • New Topic