首页 > 代码库 > 四则运算

四则运算

import java.util.Scanner;public class Jisuan {	/**	 * @param args	 */	public static void main(String[] args) {		// TODO Auto-generated method stub		 double a;		 double b;		 Scanner reader = new Scanner(System.in);		 a = reader.nextDouble();		 b = reader.nextDouble();		A jisuan = new A();			System.out.println("两者之和为:"+jisuan.add(a,b));			System.out.println("两者之差为:"+jisuan.reduce(a,b));			System.out.println("两者之积为:"+jisuan.multiply(a,b));			System.out.println("两者之商为:"+jisuan.divide(a,b));			System.out.println("a的平方为:"+jisuan.square1(a));			System.out.println("b的平方为:"+jisuan.square2(b));	}}class A{	double add(double a,double b){    	return a+b;    }    double reduce(double a,double b){    	return a-b;    }        double multiply(double a,double b){    	return a*b;    }    double divide(double a,double b){    	return a/b;    }    double square1(double a){    	return a*a;    }    double square2(double b){    	return b*b;    }}

四则运算