回复 10楼 林月儿
改过来了,但还是有问题,跟我3楼时说的问题一样。。。
3楼第一行输入1,表示只有一组用例输入啊
还是我理解错了?
import java.util.*; public class JXNU { final int π=3; class shape{ public void count() { } } public class Circle extends shape{ private double r; public Circle(double r) { this.r=r; } @Override public void count() { System.out.printf("%d",2*π*r); } } public class Square extends shape{ private double a; public Square(double a) { this.a=a; } @Override public void count() { System.out.printf("%d",4*a); } } public class Rectangle extends shape{ private double a,b; public Rectangle(double a,double b) { this.a=a; this.b=b; } @Override public void count() { System.out.printf("%d",2*(a+b)); } } public class Triangle extends shape{ private double a,b,c; public Triangle(double a,double b,double c) { this.a=a; this.b=b; this.c=c; } @Override public void count() { System.out.printf("%d",a+b+c); } } public void main(String[] args) { // TODO Auto-generated method stub int T, M; double a,b,c,r; Scanner sc=new Scanner(System.in); T=Integer.valueOf(sc.nextLine()); while(T-->0){ String[] arr = sc.nextLine().split(" ");//空格分割并转型 M=Integer.valueOf(arr[0]); if (M==1){ r=Double.parseDouble(arr[1]); Circle c1=new Circle(r); c1.count(); } else if (M==2){ a=Double.parseDouble(arr[1]); Square c1=new Square(a); c1.count(); } else if (M==3){ a=Double.parseDouble(arr[1]); b=Double.parseDouble(arr[2]); Rectangle c1=new Rectangle(a,b); c1.count(); } else if (M==4){ a=Double.parseDouble(arr[1]); b=Double.parseDouble(arr[2]); c=Double.parseDouble(arr[3]); if(a + b > c && b + c > a && a + c > b) { Triangle c1=new Triangle(a,b,c); c1.count(); } else break; } } } }
import java.util.*; public class JXNU { final int π=3; class shape{ public void count() { } } public class Circle extends shape{ private double r; public Circle(double r) { this.r=r; } @Override public void count() { System.out.printf("%d\n",2*π*r); } } public class Square extends shape{ private double a; public Square(double a) { this.a=a; } @Override public void count() { System.out.printf("%d\n",4*a); } } public class Rectangle extends shape{ private double a,b; public Rectangle(double a,double b) { this.a=a; this.b=b; } @Override public void count() { System.out.printf("%d\n",2*(a+b)); } } public class Triangle extends shape{ private double a,b,c; public Triangle(double a,double b,double c) { this.a=a; this.b=b; this.c=c; } @Override public void count() { System.out.printf("%d\n",a+b+c); } } public void main(String[] args) { // TODO Auto-generated method stub int T, M; double a,b,c,r; Scanner sc=new Scanner(System.in); T=Integer.valueOf(sc.nextLine()); while(T-->0){ String[] arr = sc.nextLine().split(" ");//空格分割并转型 System.out.println(Arrays.toString(arr)); M=Integer.valueOf(arr[0]); if (M==1){ r=Double.parseDouble(arr[1]); Circle c1=new Circle(r); c1.count(); } else if (M==2){ a=Double.parseDouble(arr[1]); Square c1=new Square(a); c1.count(); } else if (M==3){ a=Double.parseDouble(arr[1]); b=Double.parseDouble(arr[2]); Rectangle c1=new Rectangle(a,b); c1.count(); } else if (M==4){ a=Double.parseDouble(arr[1]); b=Double.parseDouble(arr[2]); c=Double.parseDouble(arr[3]); if(a + b > c && b + c > a && a + c > b) { Triangle c1=new Triangle(a,b,c); c1.count(); } else break; } } } }