问答详情
源自:3-2 Java中的算术运算符

运行成功,输出错误

public class HelloWorld{

    public static void main(String[] args) {

int age1=24;

int age2=18;

int age3=36;

int age4=27;

int sum=age1+age2+age3+age4;

int avg=(age1+age2+age3+age4)/4;

int minus=(age1-age2);

int newAge=age1++;

System.out.println("年龄总和:"+sum);

    System.out.println("平均年龄:"+avg);

System.out.println("年龄差值:"+minus);

System.out.println("自减后的年龄:"+newAge);


}

}


提问者:always顾遇 2021-06-02 21:55

个回答

  • 瓜皮瓜皮
    2021-06-02 23:03:49
    已采纳

    public class HelloWorld{

        public static void main(String[] args) {

    int age1=24;

    int age2=18;

    int age3=36;

    int age4=27;

    int sum=age1+age2+age3+age4;

    int avg=(age1+age2+age3+age4)/4;

    int minus=(age1-age2);

    int newAge=age1--;

    System.out.println("年龄总和:"+sum);

    System.out.println("平均年龄:"+avg);

    System.out.println("年龄差值:"+minus);

    System.out.println("自减后的年龄:"+newAge);


    }

    }



  • L__R
    2021-07-22 15:25:28

    public class HelloWorld{

        public static void main(String[] args) {

    int age1=24;

    int age2=18;

    int age3=36;

    int age4=27;

    int sum = age1+age2+age3+age4;

    double avg = sum/4;

    int minus = age1-age2;

    int newAge = --age1;

        System.out.println("年龄总和:"+sum);

        System.out.println("平均年龄:"+avg);

    System.out.println("年龄差值:"+minus);

    System.out.println("自减后的年龄:"+newAge);


    }

    }