本帖最后由 王怡然 于 2012-4-22 20:46 编辑
- public class Pad
- {
- private int a;
- private int b;
-
- public Pad(int a,int b)
- {
- this.a = a;
- this.b = b;
- }
- public int sum()
- {
- return a+b;
- }
- public int sub()
- {
- return a-b;
- }
- public int mul()
- {
- return a*b;
- }
- public double div()
- {
- return (double)a/b;//在这个位置上强转成double的类型即可;
- }
- public static void main(String[] args)
- {
- Pad h1=new Pad(10,4);
- h1.sum();
- h1.sub();
- h1.mul();
- h1.div();
-
- System.out.println(+h1.sum());
- System.out.println(+h1.sub());
- System.out.println(+h1.mul());
- System.out.println(+h1.div());
- }
- }
复制代码 首先我想说的第一点就是你这格式真是让人看着难受;
代码在此,解决方法给您注释上了;
|