casting of values

i have a problem. i want to return a double value by the division of two integers. the values i am getting is not as expected. for example if the lectureduration =3,and no_of_session =2, i expect to get 1.5 but i am getting 1.0.

here are some of the codes.

double calculate()

{

double i;

System.out.println(lectureduration+"\t"+no_of_session);

i=(float)(lectureduration/no_of_session);

return i;

}

public static void main(String args[])

{

prof p= new prof();

p.setsession(2);

p.setlectureduration(3);

double a=p.calculate();

System.out.println(a);

p.setsession(1);

p.setlectureduration(3);

a=p.calculate();

System.out.println(a);

}

can anyone help?

thank you.

[799 byte] By [akb205a] at [2007-9-30 2:26:07]
# 1
You need to understand that integer division results in an integer value. You cast to float casts the integer result toa float.
orbacha at 2007-7-16 13:36:04 > top of Java-index,Archived Forums,Swing...