Java Help, Plase...
Results 1 to 3 of 3

Thread: Java Help, Plase...

  1. #1
    Senior Member
    Join Date
    Dec 2001
    Posts
    134

    Java Help, Plase...

    I am having the following problem in Java simple program .

    the question is:
    write a console program to declare and initialize a double variable with some value such as 1234.5678, then retrieve the integral part of the value and store it in the variable of type long, and the first four digits of the fractionL part and store in the integer type short.
    Display the value of the double variable by outputing two values stored as integers.
    ----------
    I have gone through the class Math, and seen all the methods, abut i think there is some other way of doing it. Please help me out.
    Thanks
    regards
    harbir

  2. #2
    Senior Member
    Join Date
    Jul 2002
    Posts
    339
    I have gone through the class Math, and seen all the methods, abut i think there is some other way of doing it.
    Well there are more than one way to do it. I won't give u the details because I guess this is some sort of exercise. Since u have gone thru the class Math, now it's time to go thru the class Double (java.lang.Double). Good luck!

    Peace always,
    <jdenny>
    Always listen to experts. They\'ll tell you what can\'t be done and why. Then go and do it. -- Robert Heinlein
    I\'m basically a very lazy person who likes to get credit for things other people actually do. -- Linus Torvalds


  3. #3
    Senior Member
    Join Date
    Nov 2002
    Posts
    186
    If you didn't know, to look at the javadoc for the classes go to:
    http://java.sun.com/j2se/1.4.1/docs/api/index.html

    Find Double and look at it's methods. Here is a little snippet to get you going. I think this is the easy part anyway. The rest of it should be the challenge.
    Code:
        double i = 123.456;
        Double d = new Double(i);
        long x = d.longValue();
        System.out.println(x);
    Try this out and see what it does, the try to figure out the rest of it. Good luck!
    \"When you say best friends, it means friends forever\" Brand New
    \"Best friends means I pulled the trigger
    Best friends means you get what you deserve\" Taking Back Sunday
    Visit alastairgrant.ca

Posting Permissions

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