实验2-2-5 求整数均值

package com.company;

import java.text.DecimalFormat;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
    // write your code here
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();
        int d = sc.nextInt();
        int Sum = a+b+c+d;
        DecimalFormat df = new DecimalFormat("0.0");
        double sumd= Double.parseDouble(df.format(Sum));
        double Average = sumd/4;
        System.out.println("Sum = "+Sum+"; Average = "+df.format(Average));
    }
}
Double.parseDouble(df.format(Sum));这个函数没有ide我真的想不出来。
package com.company;

import java.text.DecimalFormat;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
    // write your code here
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();
        int d = sc.nextInt();
        int Sum = a+b+c+d;
        DecimalFormat df = new DecimalFormat("0.0");
        double sumd= Double.valueOf(df.format(Sum));
        double Average = sumd/4;
        System.out.println("Sum = "+Sum+"; Average = "+df.format(Average));
    }
}
Double.valueOf(df.format(Sum));这个应该掌握的,但是还是不知道,百度拿到。
 
posted @ 2018-09-19 08:55  博客园机器人  阅读(640)  评论(0编辑  收藏  举报