2011-09-24 20:55:26 UTC
import java.util.Scanner;
public class practice4
{
public static void main (String[] args)
{
Scanner s = new Scanner(System.in);
double F, d, D;
String A, B, C, x;
d = (1 / ((1/F) - (1/D)));
F = (1 / ((1/D) + (1/d)));
D = (1 / ((1/F) - (1/d)));
System.out.print("Do you want to solve for Focal(A), DistanceImmage(B) or DistanceObject?(C):");
x = s.nextLine();
if(x == "A")
{
System.out.print("Distance of image: ");
D = s.nextDouble();
System.out.print("Distance of object: ");
d = s.nextDouble();
System.out.print("Focal length= " + F);
}
if(x == "B")
{
System.out.print("Focal length: ");
F = s.nextDouble();
System.out.print("Distance of image: ");
d = s.nextDouble();
System.out.print("Distance of object= " + D);
}
if(x == "C")
{
System.out.print("Focal length: ");
F = s.nextDouble();
System.out.print("Distance of object: ");
D = s.nextDouble();
System.out.print("Distance of image= " + d);
}
}
}