import java.text.DecimalFormat; import java.text.NumberFormat; import java.util.ArrayList; import java.util.Scanner; public class Main{ public static void main(String[] args){ Scanner input = new Scanner(System.in); double a1,a2,b1,b2; double x1,x2,y1,y2; a1 = input.nextDouble(); b1 = input.nextDouble(); a2 = input.nextDouble(); b2 = input.nextDouble(); x1 = input.nextDouble(); y1 = input.nextDouble(); x2 = input.nextDouble(); y2 = input.nextDouble(); double n1,m1,n2,m2; n1 = Math.max(Math.min(x1, x2), Math.min(a1, a2)); m1 = Math.max(Math.min(y1, y2), Math.min(b1, b2)); n2 = Math.min(Math.max(x1, x2), Math.max(a1, a2)); m2 = Math.min(Math.max(y1, y2),Math.max(b1, b2)); if(n2>n1&&m2>m1){ NumberFormat format = new DecimalFormat("#.00"); System.out.println(format.format((m2-m1)*(n2-n1))); } else{ System.out.println("0.00"); } } }
原文:http://www.cnblogs.com/lolybj/p/6505853.html