The Artima Developer Community
Sponsored Link

Java Answers Forum
Need help with RuntimeException error

2 replies on 1 page. Most recent reply: Jun 21, 2018 7:24 PM by Karla J

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 2 replies on 1 page
Nick Boris Schwartz

Posts: 1
Nickname: nickbschwa
Registered: Dec, 2014

Need help with RuntimeException error Posted: Dec 4, 2014 1:16 AM
Reply to this message Reply
Advertisement
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 Any thoughts? Thanks!



// 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);

}

}


Priya Arrora

Posts: 5
Nickname: priya456
Registered: Aug, 2017

Re: Need help with RuntimeException error Posted: Sep 26, 2017 11:40 PM
Reply to this message Reply
Both Error and RuntimeException are unchecked exceptions, meaning that it indicate a flaw with the program, and usually should not be caught. (NullPointerException, IndexOutOfBoundsException, etc.)

I think the main difference between the two is that RuntimeException indicate there is a error with the program, and an Error is something that is fatal but out of the program's control.

Karla J

Posts: 1
Nickname: karla7
Registered: Jun, 2018

Re: Need help with RuntimeException error Posted: Jun 21, 2018 7:24 PM
Reply to this message Reply
> 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 Any thoughts? Thanks!
> gmail sign up
>
>
> // 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)) /
> I, 4)) / 90);
> TrueEplus = (float) TrueVplus - fplus1;
> Etplus = (float)(TrueEplus/TrueVplus)*100;
>
> JOptionPane.showMessageDialog (null,"Ft(i++) =
> t(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),
> ath.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);
>
> }
>
> }
>

Both Error & RuntimeException are unchecked exceptions

Flat View: This topic has 2 replies on 1 page
Topic: getting a copy of Objects and Java book Previous Topic   Next Topic Topic: Car java program help

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use