Program for focal length of a lens | Java program to determine the focal length of a lens ; Function to determine the focal length of a lens ; Driver code ; variable to store the distance between the lens and the image ; variable to store the distance between the lens and the object
import java . io . * ; class GFG { static float focal_length ( float image_distance , float object_distance ) { return 1 / ( ( 1 / image_distance ) + ( 1 / object_distance ) ) ; } public static void main ( String [ ] args ) { float image_distance = 2 ; float object_distance = 50 ; System . out . println ( " Focal ▁ length ▁ of ▁ a ▁ lens ▁ is ▁ " + focal_length ( image_distance , object_distance ) + " ▁ units . " ) ; } }