问答详情
源自: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 = 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);

 }
}


提问者:qq_年少呆萌心i_0 2017-03-10 17:58

个回答

  • 慕粉娱乐
    2017-03-10 19:32:29

    要的是自减后,你那是自增!

  • 慕标3950354
    2017-03-10 18:15:24

    int newAge=age1--;

  • 慕粉1846478040
    2017-03-10 18:06:48

    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 = 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);

     }
    }


  • leonerna
    2017-03-10 18:05:49

    int newAge = age1++的后面少了个分号