#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2014
    Posts
    3
    Rep Power
    0

    Need help with basic java code


    Hi guys. I need some help on this code. It compiles and I can get results when I run it on Netbeans but I always get RuntimeException.
    I found out on Javadocs this is the superclass of those exceptions that can be thrown during the normal operation of the Java Virtual Machine. How can I get rid of it? Any thoughts? Thanks!


    Code:
            // i++
            float Etplus, TrueEplus, TrueVplus, fplus1=0;
            //  Summation from i=1 to 10000
            for (int i=1;i<=10000;i++){
                fplus1 +=(float) 1/(Math.pow(i,4));
            }
            TrueVplus = (float) ((Math.pow(Math.PI, 4)) / 90);
            TrueEplus = (float) TrueVplus - fplus1;
            Etplus = (float)(TrueEplus/TrueVplus)*100;
       
            JOptionPane.showMessageDialog (null,"Ft(i++) = "+TrueVplus + "\n\nFa(i++) = " +fplus1 + "\n\nEt(i++) = ("+Etplus+ ")%","Results for i++ (Float)", JOptionPane.INFORMATION_MESSAGE);
           
            // i--
            float Etminus, TrueEminus, TrueVminus, fminus1=0;
    
            //  Summation from i=10000 to 1
            for (int j=10000;j>=1;j--){
                fminus1 += (double) 1/(Math.pow(j, 4));
            }
    
            TrueVminus = (double) (Math.pow((Math.PI), 4))/90;
            TrueEminus = (double) TrueVminus - fminus1;
            Etminus = (double) (TrueEminus/TrueVminus)*100;
            
            JOptionPane.showMessageDialog (null, "Ft(i--) = "
    +TrueVminus + "\n\nFa(i--) = " +fminus1 + "\n\nEt(i--) = (" +Etminus+")%","Results for i--(Float)", JOptionPane.INFORMATION_MESSAGE);
    
     }
    
    }
  2. #2
  3. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2014
    Posts
    3
    Rep Power
    0
    Hi guys. Appreciate your views but I need solutions to RuntimeExceptionHandler issue immediately. Pls pls pls......reply guys..
  4. #3
  5. Contributing User
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Aug 2010
    Location
    Eastern Florida
    Posts
    3,737
    Rep Power
    351
    I always get RuntimeException.
    Please copy the full text of the error message and paste it here. It has important info about the error.

    How can I get rid of it?
    We need the error message to see what is wrong.
  6. #4
  7. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2014
    Posts
    3
    Rep Power
    0
    Here norm: Exception in thread "main" java.lang.RuntimeException: Uncompilable source code - incompatible types: possible lossy conversion from double to float at infiniteSeries.main
  8. #5
  9. Contributing User
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Aug 2010
    Location
    Eastern Florida
    Posts
    3,737
    Rep Power
    351
    You didn't post the full error message showing the source statement where the error happened, so I'll have to guess.
    possible lossy conversion from double to float
    If you are sure the float variable will hold the data from the double, use a cast to tell the compiler that you know what you are doing:
    floatVar = (float) doubleValue.

    Comments on this post

    • MrFujin agrees : All the (double) cast in code should be changed to (float)
    Last edited by NormR; December 9th, 2014 at 06:52 PM.

IMN logo majestic logo threadwatch logo seochat tools logo