Type Casting

Classic programmed-learning exercises, refreshed for modern Java and presented in the current MrStyner.com portfolio style.

Modern Java noteThis archive has been refreshed for Java 25 LTS. Core language concepts remain useful, while outdated setup instructions and browser-era Java are labeled or replaced. Java 26 is the current feature release; Java 25 is used here as the stable teaching baseline.
go to previous page   go to home page   hear noise   go to next page
int x = 1;
int y = 9;
System.out.println( Math.sqrt( (double)x/y ) );

Answer:

Yes.

Type Casting

In the above, the integer in x is converted to double before the division is done. Now y must also be converted to double and double precision floating point division is performed.

Next the result (0.111111111) is sent to sqrt() as an argument. The expected result (0.33333333) is returned.

QUESTION 17:

Are these details a little overwhelming?