three = one + two; System.out.println("three=one+two==>"+three); three += one; System.out.println("three+=one==>"+three); three -= one; System.out.println("three-=one==>"+three); three *= one; System.out.println("three*=one==>"+three); 为什么我一个一个输出运行失败了
public class HelloWorld{
public static void main(String[] args) {
int one = 10 ;
int two = 20 ;
int three = 0 ;
System.out.println("three = one + two ==>"+ (three=one+two));
System.out.println("three += one ==>"+ (three+=one));
System.out.println("three -= one ==>"+ (three-=one));
System.out.println("three *= one ==>"+ (three*=one));
System.out.println("three /= one ==>"+ (three/=one));
System.out.println("three %= one ==>"+ (three%=one));
}
}
不用增加变量,直接输出。
public class HelloWorld{
public static void main(String[] args) {
int one = 10 ;
int two = 20 ;
int three = 0 ;
int a=three=one+two;
int b=three+=one;
int c=three-=one;
int d=three*=one;
int e=three/=one;
int f=three%=one;
System.out.println("three = one +two==>"+a);
System.out.println("three +=one==>"+b);
System.out.println("three -=one==>"+c);
System.out.println("three *=one==>"+d);
System.out.println("three /=one==>"+e);
System.out.println("three %=one==>"+f);
int
one =
10
;
int
two =
20
;
int
three =
0
;
three=one+two;
int
a=three+=one;
int
b=three-=one;
int
c=three*=one;
int
d=three/=one;
int
e=three%=one;
System.out.println(
"three=one+two ==>"
+three);
System.out.println(
"three+=one ==>"
+a);
System.out.println(
"three-=one ==>"
+b);
System.out.println(
"three*=one ==>"
+c);
System.out.println(
"three/=one ==>"
+d);
System.out.println(
"three%=one ==>"
+e);
}
}
要放在一起算 因为他每一次都运用了前一次的计算结果累计使用的,一次次的算每一次的数值都是初始的赋值 算起来当然不正确。
int one = 10 ; int two = 20 ; int three = 0 ; three=one+two; int a=three+=one; int b=three-=one; int c=three*=one; int d=three/=one; int e=three%=one; //你的所有System.out.println都错写为System.out.printlin了 System.out.println("three=one+two ==>"+three); //题目里 ==> 是要打印的内容 System.out.println("three+=one ==>"+a); System.out.println("three-=one ==>"+b); System.out.println("three*=one ==>"+c); System.out.println("three/=one ==>"+d); System.out.println("three%=one ==>"+e); }}