How do I use sqrt() and pow() math functions?

I tried starting with import java.lang.Math.*; and using sqrt() and pow(), but I get an error response in compilation.
//** 1/pi calculation program using Ramanujan's forumula **//
//** by n=2 iteration, double precision value for 1/pi repeats **//
import java.lang.Math.*;
import java.io.*;
public class CalcInversePiRamanujan {
  public static void main(String args[]) {
    double n=0, term, four_n_factorial=1, n_factorial=1, inverse_pi=0;
    inverse_pi = four_n_factorial * 1103 * 2 * sqrt(2) / 9801; //** initial value for n=0 **//
    System.out.println(inverse_pi);
    for (n=1, four_n_factorial=1, n_factorial=1; n<=3; n++) {
        four_n_factorial *= (4 * n);
        four_n_factorial *= (4*n-1);
        four_n_factorial *= (4*n-2);
        four_n_factorial *= (4*n-3);
        term = four_n_factorial;
        n_factorial *= n;
        term /= pow(n_factorial, 4);
        term *= 1103 + 26390 * n;
        term /= pow(396, 4 * n);
        term *= 2 * sqrt(2);
        term /= 9801;
        inverse_pi += term;
        System.out.println(n, term, inverse_pi);
    System.exit(0);
}

all methods in math class are static so you have to call them as
Math.pow() and Math.sqrt() you dont have to import any additional packages as Math is a class available in java.lang package
you have to change your
System.out.println(n, term, inverse_pi); to
System.out.println(n+ term+ inverse_pi);
math class also provides the value of Pi you can access it using Math.PI

Similar Messages

  • How can I use microsoft word, power point and those apps in my new iMac ? i bought this iMac yesterday so am new on tho and i would like to know

    how can I use microsoft word, power point and those apps in my new iMac ? i bought this iMac yesterday so am new on tho and i would like to know

    If you absolutely must have the Microsoft applications, you can purchase and download them from http://microsoft.com/mac.
    Free software suites LibreOffice and OpenOffice offer similar functionality (word processing and spreadsheets).
    Or you could do worse than look at Apple's Pages, Numbers and Keynote, which should already be installed in your Mac and can export to Microsoft formats if need be.
    Matt

  • How do I use Qt and OpenGL with Visual Studio

    Hi! I mainly want to program in C++ and I want to use Qt and OpenGL with Visual Studio.
    I am currently revising C++ and later on i am going to start reading Qt and OpenGL. I have a background of
    Embedded firmware design(C and Assembly).
    The Visual Studio Version I have is 2013 ultimate. How do I use Qt and OpenGL with Visual Studio?
    Thanks
    Alexandros

    Hi ClassicalGuitar,
    The forum supports VS setup and installation. And your issue is not about the forum. I will move the thread to off-topic forum. Thanks for your understanding.
    Regards,
    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

  • How can I use OmniPortlet and Web Clipping Portlet?

    How can I use OmniPortlet and Web Clipping Portlet?

    You find information on OmniPortlet and Web Clipping in the Portal Developer's Guide.
    o Building Portlets with OmniPortlet
    o Building Content-Based Portlets with Web Clipping
    Peter

  • HT2534 how do i use itunes and the app store without any credit card or gift card?

    i just got my iphone and i used to use itunes all the time before when downloading all songs were completly free, how do i use itunes and the app store to find free stuff to download without having to add a credit card or gift card with my account?

    Create a NEW account/ID for her using these instructions. Make sure you follow the instructions. Many do not and if you do not you will not get the None option. You must use an email address that you have not used with Apple before. Make sure you specify a birthdate that results in being at least 13 years old
      Creating an iTunes Store, App Store, iBookstore, and Mac App Store account without a credit card
    More details of how:
      http://ipadhelp.com/ipad-help-tips-tricks/how-to-get-free-apps-from-the-app-stor e-without-a-credit-card/

  • How can I use excel and word on the IPAD2

    How can I use excel and word documents on my Ipad 2

    There are apps such as Documents To Go which support reading/editting/creating those sorts of documents :
    standard version  -  http://itunes.apple.com/us/app/documents-to-go-office-suite/id317117961?mt=8
    premium version  -  http://itunes.apple.com/us/app/documents-to-go-premium-office/id317107309?mt=8

  • How can I use undo and redo with run time menu?

    Hi..I try to built my own menu for graphic programming. How can I use undo and redo in labview with run time menu?

    filozof-
    During runtime, by default, LabVIEW has undo/redo data changes under the edit menu. This will undo/redo changes made to controls during runtime. If you want a more extensive undo/redo (custom for your application), you are going to have to do quite a few things
    1) Create a custom runtime menu (Edit>>RunTime Menu) and place your own undo/redo controls on it
    2) Keep an action history in your program
    3) Catch the Shortcut menu event for your custom undo/redo controls
    4) Reverse the last action in your histroy when you catch the event
    This method would allow you undo entire operations (like resize, move, or whatever kind of functionality you are building into your application) unstead of just undoing data changes.
    Xaq

  • Why and how do we use CHAIN and ENDCHAIN

    Why and how do we use CHAIN and ENDCHAIN

    Hi,
    To ensure that one or more PAI modules are only called when several screen fields meet a particular condition, you must combine the calls in the flow logic to form a processing chain. You define processing chains as follows:
    CHAIN.
    ENDCHAIN.
    All flow logic statements between CHAIN and ENDCHAIN belong to a processing chain. The fields in the various FIELD statements are combined, and can be used in shared conditions.
    CHAIN.
      FIELD: <f1>, <f 2>,...
      MODULE <mod1> ON CHAIN-INPUT|CHAIN-REQUEST.
      FIELD: <g1>, <g 2>,...
      MODULE <mod2> ON CHAIN-INPUT|CHAIN-REQUEST.
    ENDCHAIN.
    The additions ON CHAIN-INPUT and ON CHAIN-REQUEST work like the additions ON INPUT and ON REQUEST that you use for individual fields. The exception is that the module is called whenever at least one of the fields listed in a preceding FIELD statement within the chain meets the condition. So <mod1> is called when one of the fields <fi> meets the condition. <mod2> is called when one of the fields <f i> or <g i> meets the condition.
    Within a processing chain, you can combine individual FIELD statements with a MODULE statement to set a condition for a single field within the chain:
    CHAIN.
      FIELD: <f1>, <f 2>,...
      FIELD  <f> MODULE <mod1> ON  INPUT|REQUEST|*-INPUT
                                  |CHAIN-INPUT|CHAIN-REQUEST.
      MODULE <mod2> ON CHAIN-INPUT|CHAIN-REQUEST.
    ENDCHAIN.
    The module <mod1> is called when screen field <f> meets the specified condition for individual fields. <mod2> is called when one of the fields <fi> or <f> meets the condition. If you use the addition ON CHAIN-INPUT or ON CHAIN-REQUEST with FIELD <f>, the condition also applies to the entire chain and module <mod1> and <mod2> are both called.
    In cases where you apply conditions to various combinations of screen fields, it is worth setting up a separate processing chain for each combination and calling different modules from within it.
    Regards,
    Ferry Lianto

  • I have lost all of my keynote templates now that I have upgraded to yosemite.  How can I use Keynotes and pages etc on my computer and not on the cloud.

    I have lost all of my previously created keynote templates now that I have upgraded to yosemite. How can I use Keynotes and pages etc on my computer and not on the cloud.

    Welcome to Apple Support Communities
    All iWork apps allow you to save your documents on your computer. You will be able to choose the destination when you want to save a document.
    You can also disable iCloud for some apps. To do that, go to System Preferences -> iCloud, press "Options" next to "iCloud Drive" and disable the apps you want to.
    If you have lost your old documents, you should have a backup that you made before upgrading to OS X Yosemite, so you only have to restore it.

  • How do you use forward and back button on mouse and use "zoom" in web browser.

    Ok so apparently this forum is ruled with an iron fist or something my very honest and truthful problems with these issues seem to have been instantly deleted in my last discussion?
    I'll try this once more.
    1) How do you use the forward and back button on a mouse without having to buy a product like Steer Mouse? There must be a way to do this without having to buy a program given it's such a useful feature that 99% of users need. I don't want to spend hours researching something that should already work. Any advice?
    2) How do you zoom in for web browsers like Chrome without it globally zooming in everything on the monitor (even background applications). I don't want to zoom in background applications. I want to be able to zoom in the web browser and still maintain all the features like the side bar, not just a little magnifying glass type thing.
    I'm currently zooming in with the CTRL-Middle Mouse button, but I can't find a way to use this feature so it's useful to browse the web it seems to not scale the browser correctly but rather is a global zoom. Any solution for this?

    Thanks so much!
    Like I said I am new to Apple products so it's still unclear to me which programs I do or don't need as I'm setting up and configuring all my software and devices.
    The Logitech Control Center appears to work perfectly for what I was trying to do!
    I accidently clicked "This helped me" instead of "This Solved My Question", sorry about that this was a solve!

  • How do i use udisksvm and traydvm

    Using newest version of Arch with newest Openbox and Tint2.
    Ive installed udisksvm, which in turn installs traydvm. This package is supposed to keep watch on attached usb devices and give me a trayicon that says something was plugged in. My problem is that there is 0 documentation on how to set it up and use it.
    udisksvm help gives this:
    udisksvm --help
    usage: udisksvm [-h] [-v] [-n] [-d]
    A GUI UDisks wrapper
    optional arguments:
    -h, --help show this help message and exit
    -v, --version show program's version number and exit
    -n, --noauto do not automount
    -d, --debug show internal infos
    traydvm help gives this:
    /usr/bin/traydvm --help
    usage: traydvm [-h] object_path
    A systray utility for udisksvm
    positional arguments:
    object_path the object to use
    optional arguments:
    -h, --help show this help message and exit
    running udisksvm gives this:
    udisksvm -d
    Found /usr/bin/traydvm
    Automounting for non optical devices enabled
    optical drive = /org/freedesktop/UDisks2/drives/HL_DT_ST_DVDRAM_GSA_4084N_5AA85B82763A
    running traydvm gives this:
    /usr/bin/traydvm
    usage: traydvm [-h] object_path
    traydvm: error: the following arguments are required: object_path
    I would like to use this program. But the help isn't helping. There is no documentation to be found. And the debug output is cryptic at best.
    Has anyone got this installed and working willing to share their step by step? Thanks.

    There are explanations in '/usr/share/udisksvm/README':
    For example, in Openbox and Tint2 with systray enabled, only add this line in
    $HOME/.config/openbox/autostart to launch udisksvm without any output:
            udisksvm >/dev/null &
    The script udisksvm runs in background, and traydvm is not meant to be run directly, it is called by udisksvm.
    Using systemd-logind.service, the session must be active for the script to have the right permissions.
    And a dbus session is also needed.
    See also https://bbs.archlinux.org/viewtopic.php?id=112397&p=3 post #53
    How do you start openbox?

  • How do i use FaceTime and iMessage on Ipad and iPhone

    I want to use FaceTime and iMessage on my iPhone and Ipad with the same Apple account but also with eachother.
    Is this possible?

    Yes it is possible.
    After you activate the apps on all of your devices with your Apple ID - you then have to add another email address at which you can be reached on all but one of the devices - and then remove your Apple ID email address as the contact address on those devices. You can keep the ID on one device as the address at which you can be reached.
    It is really very simple to do, but this user posted this some type ago and it explains how to do it. You can also Google it and find other sites that explain it. But here you go ....
    https://discussions.apple.com/thread/3395222

  • How do I use CreateBookmarksFromGroupTree and NOT guid in the name for my top level?

    Post Author: Barbdcg
    CA Forum: Deployment
    I have a report that I have created that uses uses groups and I wanted export a PDF using the CreateBookmarksFromGroupTree option. While that works, I get an ugly top level bookmark name that starts with the name of my report, then followed by a GUID;
    Report {49E72CC5-7FFD-44F8-831B-EA8F543F7D82}.rpt
    So, how do I Put in a name of my own choosing as the top-level bookmark or at least get rid of the guid?
    Any help or suggestions would be appricated.
    Thanks,
    Barb

    Post Author: Barbdcg
    CA Forum: Deployment
    Still no answer??? I can not figure this one out!!  HELP!!!

  • How do I use CreateBookmarksFromGroupTree and NOT get a "temp_" for my top level?

    I have a report that I have created that uses uses groups and I wanted export a PDF using the CreateBookmarksFromGroupTree option. While that works, I get an ugly top level bookmark name that starts with "temp_" then followed by two GUIDs "temp_13fef8e3-30ec-4bc5-ba77-b55d23c95e8f {87823BCB-7789-407C-8A7F-5096BE07A83E}".
    So, how do I:
    1) Get rid of this top level so it matches the Crystal Viewer (which has multiple top level bookmarks)
    2) Put in a name of my own choosing as the top-level bookmark.
    <!break>
    Any help or suggestions would be appricated.
    Thanks,
    Jim

    I would very much like to know how to avoid this also!!!

  • How do I use pan and zoom on vertical photographs without editing out most of the photo?

    I am trying to make a slide show.  When I have a vertically oriented (portrait) photograph and try to use pan and zoom, the feature eliminates much of the photograph.  It seems the pan and zoom feature only works for horizontally oriented (or landscape) photographs.  Is there a way to use pan and zoom on vertically oriented photographs to capture all or most of the photograph and zoom in from there?

    gtavetian
    I decided to use a different strategy to convey the principle. It is most likely that your photos will be 4:3 and you may or may not be taking them into a SD widescreen or HD widescreen project. With all those variables, to get the basic ideas across, I am going to use two models with a generalized scheme.
    For this post....
    NTSC DV Standard Project - Portrait Oriented JPG, in this case 2448 x 3264 3:4. Could be any Portrait Oriented JPEG any pixel dimensions. But best plan ahead for what you have and what you would like.
    Manually set the project preset to NTSC DV Standard.
    File Menu/New/Project and, in the new project dialog, set for NTSC DV Standard.
    Before exiting the final dialog in that area, put a check mark next to "Force Selected Project Setting on This Project". Close out of there.
    Next go to the Edit Menu/Preferences/General and remove the check mark next to "Default Scale to Frame Size". Close out of the preferences.
    In the opened Premiere Elements Expert workspace, use Add Media/Files and Folders/Project Assets to get your portrait oriented JPG to the beginning of the Timeline.The 2448 x 3264 3:4 will overwhelm the space in the Edit Mode monitor. That is to be expected. The Timeline Indicator is at the beginning of the Timeline @ 00;00;00;00.
    a. Click on the Timeline jpg to select it. With Motion Panel/Scale property (with Constrain Proportions with check mark), you want to scale the image so that the whole is shown within the mode space. You want to see the image's bounding box. See the next screenshot. The bounding box is the white outline around the image. It has handles.
    After the scaling to get that look, the important information that you want is on the right in the Motion Panel
    Position values 360.0 and 240.0
    Scale value 14.6%.
    The next phase is as before (See post 21 of this thread...but much of that is repeated below and modified for what is being described at this moment)
    With Timeline Indicator at the beginning of Video Track 1 (00;00;00;00), go to Tools Menu/Pan and Zoom and click on it to open  the Pan and Zoom workspace.
    In the Pan and Zoom workspace, you will see that the feature has created the initial two Focus Frames for you. 
    Do not do anything to Focus Frame 1 in the bin below the image window.
    Click on Focus Frame 2 in the bin below the image window and set the Focus Frame as wanted.
    Click on New Frame in the panel to the left of the image window  to create a third Focus Frame which will appear in the bin. Set Focus Frame as wanted.
    Click on New Frame in the panel  to the left of the image window to create a fourth Focus Frame which will appear in the bin. Set the Focus Frame as wanted.
    Click Done to the Pan and Zoom workspace so that you are back in the Premiere Elements Expert workspace with its Timeline.
    In the Expert workspace,
    Move the Timeline Indicator to the last frame of the selected pan and zoom clip 1. In Applied Effects Tab/Applied Effects Palette/Motion Panel expanded, (Toggle Animation should be active at this point), make sure Position settings are 360.0 and 240.0 and Scale = 14.6% (with Constrain Proportions used).Then go to Tools Menu/Freeze Frame and set the freeze frame for 3 seconds and hit Insert in Movie.
    Then move the Timeline Indicator to the first frame of the selected pan and zoom clip 1. In Applied Effects Tab/Applied Effects Palette/Motion Panel expanded (Toggle Animation should be active at this point), make sure Position settings are 360.0 and 240.0 and Scale = 14.6% (with Constrain Proportions used). Then go to Tools Menu/Freeze Frame and set the freeze frame for 3 seconds and hit Insert in Movie.
    Render.
    The Timeline content sequence from start to finish should be:
    Freeze Frame 3 seconds First Frame of pan and zoom clip 1
    Pan and zoom clip 1
    Freeze Frame 3 seconds Last Frame of pan and zoom clip 1
    Freeze Frame 3 seconds First Frame of pan and zoom clip 2
    Pan and zoom clip 2
    Freeze Frame 3 seconds Last Frame of pan and zoom clip 2
    A Dissolve/Cross Dissolve Video Transition (1.00 seconds) is placed between end of Freeze Frame  Last Frame of pan and zoom clip 1 and beginning of Freeze Frame 3 First Frame of pan and zoom clip 2.
    Additional pan and zoom portrait oriented jpgs to the Timeline would be treated as above.
    What was done above can be applied to any photo with any project preset. The basic idea is to
    a. Start with determing the whole picture Position and Scale values as described with the Default Scale to Frame Size option disabled.
    b. Do pan and zoom with Pan and Zoom Tool in its workspace
    c. Return to Premiere Elements workspace to apply your Position and Scale values to the last frame of pan and zoom clip so that the last frame presents in full clip view. Then go to the first frame of the pan and zoom clip, and apply the Position and Scale values to it so that the first frame presents in full clip view.
    d. If you want the whole view to present for more than that one frame, do the freeze frame at each end, with the wanted duration.
    e. Apply emblessments as wanted, such as video transitions, an animated graphic flying through the last scene, etc.
    We could take this same clip into a NTSC AVCHD Full HD 1080p30 project and do the same, except the Position and Scale values and the Scale % determined at the beginning and used subsequently will be different than in the NTSC DV Standard project.
    Please check out the above and see how you do with it. If problems, please indicate where and we will work through them.
    Thanks.
    ATR

Maybe you are looking for