/**编写一个接受用户输入的三个整数作为立方体的三边,
* 计算并输出这个立方体的表面积和体积
**/
import java.util.*;
public class FirstProgram
{
public static void main (String[] args)
{
int a, b, c;
System.out.print("输入3个整数作为立方体的三边:");
Scanner accept = new Scanner(System.in);
a = accept.nextInt();
b = accept.nextInt();
c = accept.nextInt();
Count result = new Count(a, b, c);
System.out.println("表面积: " + result.superficialArea());
System.out.println("体积: " + result.volume());
}
}
class Count
{
private int a;
private int b;
private int c;
Count (int a, int b, int c)
{
this.a = a;
this.b = b;
this.c = c;
}
int superficialArea ()
{
return 2 * (a * b + b * c + a * c);
}
int volume()
{
return a * b * c;
}
}本文出自 “hacker” 博客,请务必保留此出处http://anglecode.blog.51cto.com/5628271/1619836
原文:http://anglecode.blog.51cto.com/5628271/1619836