标签:
一、
(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();
}
}
标签:
原文地址:http://www.cnblogs.com/zzdsbc/p/5392950.html