@@ -0,0 +1,2139 @@
+package java_problems.beginner;%0D%0A%0D%0Aimport java.util.Scanner;%0D%0A%0D%0A/*%0D%0A * Professor Snape has lots of potions. Bottles containing all types of potions%0D%0A * are stacked on shelves which cover the entire wall from floor to ceiling.%0D%0A * Professor Snape has broken his bones several times while climbing the top%0D%0A * shelf for retrieving a potion. He decided to get a ladder for him. But he has%0D%0A * no time to visit Diagon Alley. So he instructed Ron Weasley to make a ladder%0D%0A * for him. Professor Snape specifically wants a step ladder which looks like an%0D%0A * inverted 'V' from side view.%0D%0A * %0D%0A * Professor just mentioned two things before vanishing-%0D%0A * B - separation between left side (LS) and right side (RS) on the ground%0D%0A * LS - the length of left side%0D%0A * %0D%0A * What should be the length of RS? At one extreme LS can be vertical and at%0D%0A * other RS can be vertical. Ron is angry and confused. Since Harry is busy%0D%0A * battling Voldemort, its your duty to help him find the minimum and maximum%0D%0A * length of RS.%0D%0A * %0D%0A * Input: %0D%0A * First line contains single integer T, the number of test cases. Then T lines%0D%0A * follow each containing 2 integers - B and LS.%0D%0A * %0D%0A * Output: %0D%0A * Output T lines, each containing minimum value of RS and maximum value of RS,%0D%0A * separated by space. The answer (RS) will be considered correct if it has%0D%0A * relative and absolute error less than 10-2.%0D%0A * %0D%0A * Constraints: %0D%0A * 1 %3C= T %3C= 1000%0D%0A * 1 %3C= B %3C LS %3C= 1000%0D%0A * %0D%0A * Example %0D%0A * Input:%0D%0A * 3%0D%0A * 4 5%0D%0A * 10 12%0D%0A * 10 20%0D%0A * %0D%0A * Output:%0D%0A * 3.0 6.40312%0D%0A * 6.63325 15.6205%0D%0A * 17.3205 22.3607%0D%0A */%0D%0Apublic class SnapeAndLadder %7B%0D%0A%0D%0A%09public static void main(String%5B%5D args) %7B%0D%0A%09%09%0D%0A%09%09Scanner sc = new Scanner(System.in);%0D%0A%09%09int numCases = Integer.parseInt(sc.nextLine());%0D%0A%09%09%0D%0A%09%09for (int i = 0; i %3C numCases; i++) %7B%0D%0A%09%09%09int B = sc.nextInt();%0D%0A%09%09%09int LS = sc.nextInt();%0D%0A%09%09%09outputMinMaxRS(B, LS);%0D%0A%09%09%09System.out.println();%0D%0A%09%09%7D%0D%0A%09%09sc.close();%0D%0A%09%7D%0D%0A%09%0D%0A%09private static void outputMinMaxRS(int B, int LS) %7B%0D%0A%09%09double min = Math.sqrt((LS * LS) - (B * B));%0D%0A%09%09double max = Math.sqrt((B * B) + (LS * LS));%0D%0A%09%09System.out.printf(%22%25.5f %25.5f%22, min, max);%0D%0A%09%7D%0D%0A%7D

Add SnapeAndLadder