• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

error not showing

 
Ranch Hand
Posts: 290
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
public class vote
{
static int i;
int g=100;
int p=100;
public void lapore(float f)
{
f=0.0f;
float i=(g)+(g++)+(-g/f)+(12);
System.out.println(" "+i);
}
public static void main(String[]args)
{
long i=10l;
vote v=new vote();
v.lapore(i);
}
}
Hello expert's
In the above given code, i would like to know that in line number 4 i have initialized varaible g with 100 then in line number 9 i have put the negative sign in front of the variable g.My question is,why did not the compile show any error?.Pleas throw some light on it.
 
Sheriff
Posts: 17644
300
Mac Android IntelliJ IDE Eclipse IDE Spring Debian Java Ubuntu Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
ArithmeticException is raised only for Integer division. Division by zero in floating point expressions does not raise an exception. Since f == 0.0f, -g is converted to float before the division operation is carried out and the floating point expression (-g/f) evaluates to Float.NEGATIVE_INFINITY.
J.Lacar
 
nitin sharma
Ranch Hand
Posts: 290
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
sir, my question is something else, i know that what u have explained.My Question is whaen i declared g,i did not put any negative sign in front of g but when i used that varaible g in an expression,i have put negative sign in front of g.why is that not showing any error.?
 
Ranch Hand
Posts: 111
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi nitin,
what i can infer is u r confusing with the "-" unary operator and the negative sign before a numeric.even if an int is declared positive ,it can be negated later on by using this operator coz this operator is not only assigned to literal values but can be applied to expressions as well.
hope that helps
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic