I am new to JAVA, and I am trying to learn the language; please excuse me if I am being silly.
So I was testing out Math.Pow( ) and came across that when I use a division function in the second argument my result is always '1.0', no matter what the values I put in both the arguments. Help?
public static void main(String[] args) {
double a= 27 , b = 1/3 ;
System.out.println(Math.pow(a,b));
}
run: 1.0 BUILD SUCCESSFUL (total time: 0 seconds)
1/3is zero.Math.pow(a,0)is1for alla != 0, in particular fora = 27.The
1/3division is performed between two integers using integer division, before the result is converted to adouble. You can get the result you are looking for by ensuring that the number is done using double division, e.g.1.0/3.