实验一简单的加减乘除

一、

(1)

package com.lxb.cn;

public class Calculation {
double a;
double b;
public void sum(){
System.out.println(a+b);
}
public void sub(){
System.out.println(a-b);
}
public void mul(){
System.out.println(a*b);
}
public void div(){
if(b!=0){
System.out.println(a/b);
}
else{
System.out.println("无法计算");
}

}
}

(2)

package com.lxb.cn;

public class Test {
public static void main(String[] args){
Calculation cal = new Calculation();
java.util.Scanner input = new java.util.Scanner(System.in);
System.out.println("输入a值");
double a = input.nextDouble();
System.out.println("输入b值");
double b = input.nextDouble();
cal.a = a;
cal.b = b;
cal.sum();
cal.sub();
cal.mul();
cal.div();
}
}

posted on 2016-04-14 21:50  林海永青  阅读(169)  评论(0编辑  收藏  举报