Why is my code only working sometimes?

This code is supposed to find the sum of the digits in the number 2^1000. However, it returns a decimal that is way off. And, for some reason, if 2^15 or 2^4 or other smaller exponents are used, the code works perfectly. Why is it taking exception with 1000 as an exponent??
public double TwoToTheThousand() { //Adds all the digits together of the number 2^1000
double tens = 10.0;
double sum = 0.0;
double num = Math.pow(2, 1000);
double temp = Math.pow(2, 1000);
for(double a = 0; a > -1; a++) {
if(tens/10 > num)
return sum;
sum += ((num % tens)/(tens/10.0));
num -= (temp%tens);
temp = num;
tens*=10.0;
return -1.0;
}

Are you sure that Double can hold such a huge number?
I don't think so...
Edited by: sadrayan on Oct 7, 2008 7:46 AM

Similar Messages

  • HT204389 Why does talk text only work sometimes?????  At times it works fine and then it will either show me the blue circles forever or just stop without converting anything I said.

    Why does talking to Siri only work periodically????  Sometimes it does fine and other times it just keeps running and nothing happens!     When I am tring to talk to text in messeges it does the same thing.  Sometimes fine,  other times the blue circles forever and then...nothing !  Does this happen to others???  Does anyone have a solution to this???

    The trascription doesn't take place on your phone. The audio file is processed a little on the phone and then sent to Apple's servers for the bulk of the work, and the resulting text is sent back to your phone.
    Sometimes there might be problems connecting to the internet to send the file. Sometimes there might be problems with Apple's servers in a specific region. In my case if I go outside my house a bit my phone will still be trying to connect to the wifi (there is just a little bit of a signal). There isn't enough wifi to handle sending the audio files to Apple, but enough that the phone keeps trying to use it.
    Things that sometimes help. Turn off wifi if it is weak. Put your phone into airplane mode for a few seconds and then turn the radio back on.
    If the problem is at Apple's end. Just wait a while.

  • Why does the keyboard shortcut on the bookmarks ctrl end and ctrl home to go up and down the bookmarks only work "sometimes"

    Why does the keyboard shortcut on the bookmarks ctrl end and ctrl home to go up and down the bookmarks only work "sometimes"

    Is the problem on the Bookmarks menu, on the Bookmarks drop-down list (from one of your toolbars), in the Bookmarks sidebar, or in the Library dialog used to organize bookmarks?
    Do Home and End (without the Ctrl key) work any better/differently?

  • My Ringer only works sometimes with I message only

    My Ringer only works sometimes when using I message. The ringer works for all phone calls and emails.  I have tried everything, I even had the unit switched by my carrier and it's happening with the latest unit as well. I did not do the I tunes back and restore. I did a manual set up thinking the problem might carry over from the previous unit. Help!

    Had this happen today and 2X past as you discribed. A reboot (turn phone off and on) restored all sounds for me. The first time I can't associate w/ a cause but the second and third were just after listening to a podcast using the apple podcast app - the only app available for that. That's my story and for now I'm sticking to it.

  • IPhoto 08 only works SOMETIMES with iPhone....

    iPhoto 08 only works SOMETIMES with iPhone. I have been able to upload my photos from my iPhone SOMETIMES... Other times iPhoto doesn't recognize that the iPhone is plugged in. The IMPORT photos just NEVER showes up. How can I get it to CONSISTANTLY recognize my iPhone... what is wrong? Never had this problem with 06.

    ok, here's what i did to get iphoto to recognize my iphone.
    change the "connecting camera opens:" dialogue box to "image capture" (in the iphoto preferences "general" tab @ the bottom of the window)
    close the preferences & quit iphoto.
    quit itunes
    open iphoto & change the "connecting camera opens:" dialogue box back to "iphoto"
    close the preferences & quit iphoto
    plug in iphone.
    both itunes & iphoto will launch simultaneously.
    best of luck!
    --e--

  • FPGA code only works on alternate executions

    Hi,
    I have some code I wrote for FPGA which, by itself, works fine. I tried to use "Open FPGA VI Reference" as part of a previous (non-FPGA based) VI. However, I find that the full code only works on alternate executions. I thought this may be because the FPGA VI is not being reset properly. However, I have used "Close FPGA VI Reference" and chose "Close and Reset" and the problem remains.
    Any help is appreciated,
    Thanks.

    Hi Gary,
    I hope you are doing well today! What version of LabVIEW FPGA are you using? When you say you are doing 'alternate executions', what exactly do you mean? Do you run your host VI, stop it and then run it again? Have you tried just using Close instead of resetting the FPGA VI? Also, what are you using the reference for? What are you invoking? It would, also, be better if you post a screenshot of your VI.
    Adnan Zafar
    Certified LabVIEW Architect
    Coleman Technologies

  • Why is my airportxpr only working with Itunes and not with another music program

    why is my airportxpr only working with Itunes and not with another music program??
    I can not select/see other outputs in my sound selector.

    You have not indicated which OS or which music program you have so I have listed a program called Airfoil to try for both Windows and Mac - it may work for you
    for Windows - http://rogueamoeba.com/airfoil/windows/
    for Mac - http://rogueamoeba.com/airfoil/mac/

  • My phone's speakers only work sometimes. Sometimes it is better when I plug in my headphones, but not all of the time. Any idea's?

    My phone's speakers only work sometimes. It started recently, and I just moved to Hawaii so I am at the beach alot. Could sand have something to do with this? Sometimes it is better when I plug in my headphones, but not all of the time. Any idea's?

    cmhatch93 wrote:
    I just moved to Hawaii so I am at the beach alot. Could sand have something to do with this?
    Absolutely!
    If you are taking your $500 electronic device to the beach, I recommend you get a case that completely seals the iPhone from the elements (ie. waterproof).
    -> http://reviews.cnet.com/8301-19512_7-57587098-233/top-waterproof-iphone-5-and-ip hone-4-4s-cases/

  • HT4623 The audio only works sometimes on videos on YouTube,Facebook,vine...etc. Please tell me how to fix it!!!

    Audio only works sometimes on videos and the volume buttons on the side only work sometimes,very aggrivating, please help!!

    Hello Tetnus,
    Thanks for using Apple Support Communities.
    For more information on this, take a look at:
    iPhone: No sound or distorted sound from speaker
    http://support.apple.com/kb/ts5180
    If an audio issue occurs when using a specific application, try testing other applications to see if the issue persists.
    If the iPhone is paired with a Bluetooth headset or car kit:
    Try turning off Bluetooth.
    If you experience difficulties with the Bluetooth feature, follow these troubleshooting steps.
    Restart the iPhone.
    If restarting doesn't fix the issue, ensure that your iPhone is updated to the latest version of iOS.
    If the issue is not resolved after restoring the iPhone software, please contact Apple Support.
    Best of luck,
    Mario

  • IiPad only works sometime with  hp-b210

    IPAD only works sometimes with my HP B210 printer

    Hi there sahmrh47,
    I would recommend taking a look at the troubleshooting steps found toward the bottom of the article below.
    AirPrint Basics
    http://support.apple.com/kb/HT4356
    -Griff W.

  • Hi my lock button only works sometimes on my iphone 5 , could this be because i have not updated to ios 7 yet

    hi my lock button only works sometimes on my iphone 5 , could this be because i have not updated to ios 7 yet, thanks for the help!

    No.
    You're welcome.

  • My delphi code only works in DAQ driver 6.6 but not in upper version. Why?

    Hi,
    I'm using delphi 6 to program my application. My code was working fine if I'm using DAQ driver 6.6. Now I want to update my driver, but my code doesn't work. It doesn't work for another version of driver, except 6.6. My program will crash if not using 6.6. I'm not using ActiveX controls to communicate with the card. I'm using dll instead. I wonder is it some functions in 6.6 no longer exist in upper version. My code is in the attachment. Thank you
    Attachments:
    DAQInterface.pas ‏39 KB

    Hello;
    That is probably the case there. One thing you can do to double check if that is actually the problem is to probe each NI-DAQ function and see which one is giving you the error.
    Then, you can open the NI-DAQ on line help and search for the function you used on your code. If you can't find it, that means the new version of the driver doesn't support that function anymore.
    Hope this helps.
    Filipe A.
    Applications Engineer
    National Instruments

  • Repaint() an applet from a swing applet, why does this code not work?

    below are three files that work as planned except for the call to repaint(). This is envoked when a button is hit in one applet and it should repaint another applet. I opened them up in a html file that simply runs both applets. If you could see why the repaint doesn't work I'd love to know. good luck.
    //speech1
    import java.awt.*;
    import java.applet.Applet;
    import java.awt.event.*;
    //java extension packages
    import javax.swing.*;
    public class speechapp1 extends JApplet implements ActionListener{
    // setting up Buttons and Drop down menus
    char a[];
    Choice choicebutton;
    JLabel resultLabel;
    JTextField result;
    JLabel enterLabel;
    JTextField enter;
    JButton pushButton;
    TreeTest PicW;
    // setting up applets G.U.I
    public void init(){
    // Get content pane and set it's layout to FlowLayout
    Container container = getContentPane();
    container.setLayout( new FlowLayout() );
    // initialise buttons and shit
    a = new char[30];
    choicebutton = new Choice();
    enterLabel = new JLabel("Test");
    enter = new JTextField(30);
    resultLabel= new JLabel("speech label");
    result = new JTextField(30);
    result.setEditable(false);
    // Add items to Choice Button
    choicebutton.addItem("abc");
    choicebutton.addItem("def");
    choicebutton.addItem("ghi");
    choicebutton.addItem("jkl");
    pushButton = new JButton("Click to continue");
    // Add new Tree from file TreeTest.java
    PicW = new TreeTest();
    // Add buttons to container.
    container.add(resultLabel);
    container.add(result);
    container.add(enterLabel);
    System.out.println("");
    container.add(choicebutton);
    System.out.println("");
    container.add(pushButton);
    pushButton.addActionListener(this);
    //choicebutton.addActionListener( this );
    // Set the text in result;
    result.setText("Hello");
    //public void paint(Graphics gg){
    // result.setText("Hello");
    public void actionPerformed(ActionEvent event){
    // continue when action performed on pushButton
    String searchKey = event.getActionCommand();
    System.out.println("");
    if (choicebutton.getSelectedItem().equals("abc"))
    PicW.getPicWeight(1);
    if (choicebutton.getSelectedItem().equals("def"))
    PicW.getPicWeight(2);
    if (choicebutton.getSelectedItem().equals("ghi"))
    PicW.getPicWeight(3);
    if (choicebutton.getSelectedItem().equals("jkl"))
    PicW.getPicWeight(4);
    System.out.println("repainting from actionPerformed method()");
    PicW.repaint();
    import java.applet.Applet;
    import java.awt.*;
    import java.util.*;
    public class TreeTest extends Applet{
    Tree BackgroundImageTree;
    Tree PlayerImageTree;
    Image snow,baby;
    int weight;
    public void getPicWeight(int w){
    weight = w;
    System.out.println("the new weight has been set at: "+weight);
    this.repaint();
    public void init()
    // initialising trees for backgound images and player images
    BackgroundImageTree = new Tree();
    PlayerImageTree = new Tree();
    // initialising images and correcting size of images to correctly fit the screen
    snow = getImage(getDocumentBase(),"snow.gif");
    baby = getImage(getDocumentBase(),"baby.gif");
    // inserting images into correct tree structure
    System.out.println("inserting images into tree: ");
    // inserting background images into tree structure
    BackgroundImageTree.insertImage(1,snow);
    // inserting players into tree structure
    PlayerImageTree.insertImage(1,baby);
    public void paint(Graphics g){
    System.out.println("Searching for selected Image");
    if((BackgroundImageTree.inorderTraversal(1)==null)&&(PlayerImageTree.inorderTraversal(1)==null)){
    System.out.println("There is no tree with the selected value in the trees");
    }else{
    g.drawImage(BackgroundImageTree.inorderTraversal(1),1,3,this);
    //g.drawImage(PlayerImageTree.inorderTraversal(1),55,150,this);
    import java.awt.*;
    import java.applet.Applet;
    class TreeNode {
    TreeNode left;
    Image data;
    TreeNode right;
    int value;
    public TreeNode(int weight,Image picture){
    left = right = null;
    value = weight;
    data = picture;
    public void insert(int v, Image newImage){
    if ( v< value){
    if (left ==null)
    left = new TreeNode(v,newImage);
    else
    left.insert(v,newImage);
    else if (v>value){
    if (right ==null)
    right = new TreeNode(v,newImage);
    else
    right.insert(v, newImage);
    public class Tree{
    private TreeNode root;
    public Tree() {
    root = null;
    public void insertImage(int value, Image newImage){
    if (root == null)
    root = new TreeNode(value,newImage);
    else
    root.insert(value,newImage);
    // in order search of tree.
    public Image inorderTraversal(int n)
    return(inorderHelper(root,n));
    private Image inorderHelper(TreeNode node, int n){
    Image temp = null;
    if (node == null)
    return null;
    if (node.value == n ){
    return(node.data);
    temp = inorderHelper(node.left,n);
    if (temp == null){
    temp = inorderHelper(node.right,n);
    return temp;
    }

    I can fix your problems
    1. You get an error here because you can only invoke the superclass's constructor in the subclass's constructor. It looks like that's what you're trying to do, but you're not doing it right. Constructors don't return any value (actually they do, but it's implied, so you don't need the void that you've got in your code)
    2. I'm not sure, but I think your call to show might be wrong. Move the setsize and setvisible calls to outside of the constructor

  • URL Checker - only working sometimes?

    Hi,
    I've built a URL checker (to see if a URL exists or not) code below:
    import java.net.*;
    import java.io.*;
    public class respCode
    public static void main ( String[] args )
    throws IOException  
              try    
              URL url = new URL( args[0] );     
              URLConnection c = url.openConnection();         
                   for (int i=0; ; i++)      
                   String name = c.getHeaderFieldKey(i);           
                   String value = c.getHeaderField(i);               
                        if (name == null && value == null)     // end of headers           
                        break;                    
                        if (name == null)     // first line of headers           
                        System.out.println("Server HTTP version, Response code:");             
                        System.out.println(value);             
                        System.out.print("\n"); 
                             if(value.equals("HTTP/1.1 200 OK"))
                             System.out.println("OK");
                             else
                             System.out.println("Not OK");
              catch (Exception e)
    }But it's only working for some addresses and not others. For example, if I use a page that actually exists (e.g. www.facebook.com) I get an OK which is correct then a sub-page of this site which doesn't exist (e.g. www.facebook.com/sgboegoeb) I get a 'Not OK' which is also correct.
    BUT if I use a URL which doesn't exist at all (e.g. www.lgnwpo.com) I get back a 200 response code and an OK. Can anyone tell me why this is happening? Am I getting redirected to a genuine page or something?
    V grateful for any help given! :-)

    As a general rule, when I see this:
    catch (Exception e)
              } My reply is:
    Fix your empty catch block with an e.printStackTrace() or a System.out.println(e.toString()) and then ask. When you do something like you have done and purposefully put an empty catch block in there, you are saying: "I don't want to know..." Now you want to know: fix it.

  • After latest FP update, why does my website only work in Firefox.

    I spent ages the other night trying to fix my website, as it suddenly stopped working in IE9. Tried all sorts of FP installs with no avail. Eventually went back to IE8, think 9 was the problem, and still my site won't work. Out of 4 browsers, IE8 (or 9), Opera, Safari and FF, only FF displays my site. If I understand correctly, FF doesn't use the same plugin as the rest. My question is, why does it only work in one browser, and not the others.
    If I use my HTC Desire, the site works fine too.
    Just to be clear though, this isn't just on one PC, it is on three. I have one running Win7 64-Bit, one running XP Pro, and one running Vista Business. None of them will display the site with IE8. Oh, and my WIn7 machine dual boots with XP Home, and that doesn't work either.
    Even my Vista Business machine, which actually hosts the site, won't display it properly.
    The site was created using SWF files built in Flash CS3, if that's relevant. One AS2 file, and 2 AS3 files on a page (usually)
    You can check the site here www[DOT]digital[DASH]essence[DOT]co[DOT]uk
    Sorry for the unfriendly address, I don't trust forums and website addresses.

    It's the forums that make the image tiny, if you do a right-click > copy shortcut, you can then paste it into a new tab, which will let you see the full size image. It's a 3360x1050 image, maybe a bit big for the forums.
    Basically though, the left image is IE, and that shows an error box. The centre image is Opera, and that shows an empty screen. The right image is FF, and that is how it should look.
    If it's a machine specific error, then I can't work out why it is on several machines in my house... very odd.

Maybe you are looking for

  • Flash drive not shown in File Explorer

    I have plugged in my flash drive into three different usb drive ports (one at a time) and no luck on opening documents on it. Its icon shows on the bottom bar of the desktop, however it is unable to access. I have restarted my computer to see if it w

  • Many Problems with the update in July

    After I got the latest QT Update in July I could no Longer use my MLB Gameday Audio. Also I could not watch the latest Keynote Address. Anyone else having these problems?

  • [Solved] Dovecot imap-login fails

    I have been working on this for hours and I have little idea what is wrong. I have dovecot setup to authenticate via PAM. I am sure that the PAM authentication is correct as a wrong password returns a bad auth error. However, when the initial authent

  • Search logic in servlete programming

    Hi i hae a search text box in jsp.. in the servlet i need write logic for retrieving the values n diaplsyiing...could ne1 tell me how to do it?thank yu

  • Why does Premiere Elements 10 crash when I select transitions.

    Any time I try to select the transition tool the program crashes. Everything else seems to work just fine. I'm working in windows 7.