用java语言写一个方法,求两个double数据的和

2025-04-05 11:52:46
推荐回答(3个)
回答1:

public class SumDemo{
    public static void main(String[] args){
        double sum = getSum(1.2,2.3);
        System.out.println("和为:" + sum );
    }
    public static double getSum(double a, double b){
        return a + b;
    }
}

回答2:

double a = 23.0;
double b = 33.0;
double sum = a + b;
System.out.println("结果是:"+sum);

回答3:

public class Tests {
public static void main(String[] args) {
double c=sum(1.2,3.2);
System.out.println(c);
}
public static double sum(double a,double b){
return a+b;
}
}