才不是蠢鱼
2017-08-25 16:53
int one = 10 ;
int two = 20 ;
int three=one+two;//这样子是可以的,但是改成两步:int three=0;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);
three%=one;
System.out.println("three %= one ==> "+three);
你的第一种写法int three=one+two,这样写虽然能够实现出来,在慕课网的编辑器中看不出来问题。但在eclipse中会有警告提示。所以这种写法是不对的,这样写的话变量three的值是不被使用的,这样就没有意义了。
我重新按照你的来弄了一遍,得到的输出是这样的
three = one + two ==>30<br/>three += one ==>40<br/>three -= one ==>30<br/>three *= one ==>300<br/>three /= one ==>30<br/>three %= one ==>0<br/>
应该要怎么样才能去掉<br/>呢?
我这样写的,是没问题的。
public class HelloWorld{
public static void main(String[] args) {
int one = 10 ;
int two = 20 ;
int three = 0 ;
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);
three /= one ;
System.out.println("three /= one ==>"+three);
three %= one ;
System.out.println("three %= one ==>"+three);
貌似同一个类型&&同一个变量,不能被连续分别赋值。
我试过了这么写也没错,不行你就试着不要改动他原来的代码,把three的运算写在println后面的括号里面。
Java入门第一季(IDEA工具)升级版
1165172 学习 · 17581 问题
相似问题