zhouxq
import java.util.*; public class Main { public static void main(String[] args){ Scanner in = new Scanner(System.in); while(true){ String s = in.nextLine(); String[] a = s.split(" "); Shape shape = null; switch(a.length){ case 1: shape = new Circle(Double.parseDouble(a[0])); break; case 2: shape = new Rectangle(Double.parseDouble(a[0]), Double.parseDouble(a[1])); break; case 3: shape = new Triangle(Double.parseDouble(a[0]), Double.parseDouble(a[1]), Double.parseDouble(a[2])); break; } System.out.printf("%.2f\n", shape.length()); } } } interface Shape{ double length(); } class Circle implements Shape{ public double length() { return Circle.PI * 2.0 * r; } private double r; static final double PI = 3.14; public Circle(double r){ if(r <= 0) this.r = 0; else this.r = r; } } class Rectangle implements Shape{ private double l, h; public Rectangle(double l, double h){ if(l <= 0 || h <= 0){ this.l = 0; this.h = 0; } else{ this.l = l; this.h = h; } } public double length(){ return (l+h) * 2.0; } } class Triangle implements Shape{ private double a, b, c; public boolean True(double ...c){ Arrays.sort(c); //System.out.println(c[0] +" " + c[1] + " " + c[2]); if(c[0]+c[1] > c[2]) return true; else return false; } public Triangle(double a, double b, double c){ if(a <= 0 || b <= 0 || c <= 0 || True(a, b, c) == false){ this.a = 0; this.b = 0; this.c = 0; } else{ this.a = a; this.b = b; this.c = c; } } public double length(){ return a + b + c; } }