aspose file tools*
The moose likes Beginning Java and the fly likes New to java Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "New to java" Watch "New to java" New topic
Author

New to java

jodi clark
Greenhorn

Joined: Jul 13, 2004
Posts: 10
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

Joined: Nov 22, 2008
Posts: 18944
One of the faults in the programm is

should be

= : is an assignment operation
== : is comparison

bye
jodi clark
Greenhorn

Joined: Jul 13, 2004
Posts: 10
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

Joined: Jan 12, 2004
Posts: 384
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 ]

How simple does it have to be???
jodi clark
Greenhorn

Joined: Jul 13, 2004
Posts: 10
:roll:

ummm which one, where? did i happen to mention i was clueless?
Davy Kelly
Ranch Hand

Joined: Jan 12, 2004
Posts: 384
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

Joined: Jul 13, 2004
Posts: 10
ugh...totally missed that.
Thanks
jodi clark
Greenhorn

Joined: Jul 13, 2004
Posts: 10
=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

Joined: May 03, 2004
Posts: 3
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

Joined: Jul 13, 2004
Posts: 10
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

Joined: Jul 08, 2003
Posts: 24187
    
  34

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?


[Jess in Action][AskingGoodQuestions]
jodi clark
Greenhorn

Joined: Jul 13, 2004
Posts: 10
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

Joined: Jan 29, 2003
Posts: 8791
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 ]

A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
Darin Niard
Ranch Hand

Joined: Jun 08, 2004
Posts: 118
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

    Joined: Jul 13, 2004
    Posts: 10
    thank you all for ur assistance
    Davy Kelly
    Ranch Hand

    Joined: Jan 12, 2004
    Posts: 384
    have you got it working the way you want it?

    Davy
    jodi clark
    Greenhorn

    Joined: Jul 13, 2004
    Posts: 10
    Yes tyvm, it is =0)
     
    I agree. Here's the link: http://aspose.com/file-tools
     
    subject: New to java