Advertisement
Chaosfirebolt

Resurrection Dynamic Pattern

Nov 17th, 2017
153
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.56 KB | None | 0 0
  1. import java.io.BufferedReader;
  2. import java.io.IOException;
  3. import java.io.InputStreamReader;
  4. import java.text.DecimalFormat;
  5.  
  6. /**
  7.  * Created by ChaosFire on 17.11.2017 г.
  8.  */
  9. public class ResurrectionSecond {
  10.  
  11.     public static void main(String[] args) throws IOException {
  12.         BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
  13.         int phoenixCount = Integer.parseInt(reader.readLine());
  14.         StringBuilder output = new StringBuilder();
  15.         for (int i = 0; i < phoenixCount; i++) {
  16.             double bodyLength = Double.parseDouble(reader.readLine());
  17.             String width = reader.readLine();
  18.             double bodyWidth = Double.parseDouble(width);
  19.             double wingLength = Double.parseDouble(reader.readLine());
  20.  
  21.             double years = bodyLength * bodyLength * (bodyWidth + 2 * wingLength);
  22.             DecimalFormat decimalFormat = getFormat(width);
  23.             output.append(decimalFormat.format(years)).append(System.lineSeparator());
  24.         }
  25.         reader.close();
  26.         System.out.print(output);
  27.     }
  28.  
  29.     private static DecimalFormat getFormat(String input) {
  30.         int accuracy;
  31.         String[] data = input.split("\\.");
  32.         if (data.length < 2) {
  33.             return new DecimalFormat("0");
  34.         } else {
  35.             accuracy = data[1].length();
  36.         }
  37.         StringBuilder pattern = new StringBuilder("0.");
  38.         for (int i = 0; i < accuracy; i++) {
  39.             pattern.append("0");
  40.         }
  41.         return new DecimalFormat(pattern.toString());
  42.     }
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement