Results 1 to 6 of 6
Like Tree1Likes
  • 1 Post By Fubarable

Thread: stuck at isInfinite and isNan....please help

  1. #1
    Cosmos is offline Member
    Join Date
    Jul 2011
    Location
    New Delhi,India
    Posts
    56
    Rep Power
    0

    Question stuck at isInfinite and isNan....please help

    public class InfNaN {
    public static void main(String[] args) {
    Double d1=new Double(1/0.);
    Double d2=new Double(0/0.);
    System.out.println("Infinite:"+d1.isInfinite()+"\n Not a number:"+d1.isNaN());
    System.out.println("Infinite:"+d2.isInfinite()+"\n Not a number:"+d2.isNaN());
    }
    }

    this is my program...i want to ask what is the use of .(dot) in Double class constructor(i.e.what it means by 1/0.???)
    i wrote the program without using .(dot) and i got the exception of divide by zero.....

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    26

    Default

    Without the dot you're working with ints, not doubles and doing int division, not double division, and as you're finding out, they behave differently.
    Cosmos likes this.

  3. #3
    Cosmos is offline Member
    Join Date
    Jul 2011
    Location
    New Delhi,India
    Posts
    56
    Rep Power
    0

    Default

    that means by double division we can divide a number by zero and we wont get divide by zero exception????

  4. #4
    Cosmos is offline Member
    Join Date
    Jul 2011
    Location
    New Delhi,India
    Posts
    56
    Rep Power
    0

    Default

    thanks bro....i got my answer....

  5. #5
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    26

    Default

    Quote Originally Posted by Cosmos View Post
    that means by double division we can divide a number by zero and we wont get divide by zero exception????
    No need for us to tell you anything as you can see the results for yourself in your code's output. But if you want to learn more about this, check out what the Java Language Specification (JLS) has to say about this: JLS 15.17.2 Division Operator /

  6. #6
    Cosmos is offline Member
    Join Date
    Jul 2011
    Location
    New Delhi,India
    Posts
    56
    Rep Power
    0

    Default

    just one more question bro.....

    so the dot is something like a convertor that converts int to double or float?????

Similar Threads

  1. Really stuck need help
    By B_Tank88 in forum New To Java
    Replies: 45
    Last Post: 07-18-2011, 08:52 PM
  2. I'm stuck help!!!
    By nobody58 in forum Advanced Java
    Replies: 2
    Last Post: 03-18-2010, 03:52 PM
  3. Stuck in sea
    By programmer_007 in forum JDBC
    Replies: 1
    Last Post: 09-17-2009, 05:00 AM
  4. Im on my last lab!!!! And im stuck...:(
    By clanboru15 in forum New To Java
    Replies: 5
    Last Post: 03-13-2009, 02:44 AM
  5. really stuck now..
    By shongo in forum Advanced Java
    Replies: 2
    Last Post: 11-09-2008, 03:56 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •