幕布斯656111
2018-09-18 10:10
public class HelloWorld{
public static void main(String[] args) {
int one = 10 ;
int two = 20 ;
int three = 0 ;
int three=one+two;
System.out.println("three=one+two==>"+three);
int three+=one;
System.out.println("three+=one==>"+three+);
int three-=one;
System.out.println("three-=one==>"+three-);
int three*=one;
System.out.println("three*=one==>"+three*);
int three/=one;
System.out.println("three/=one==>"+three/);
int three%=one;
System.out.println("three%=one==>"+three%);
int one = 10 ; int two = 20 ; int three = 0 ; //为three赋值运算结果 three = one+two; //10+20 three 为30 System.out.println(""+three); three=three+=one; //30+10 three 为40 System.out.println(three); three = three-=one; //类推 System.out.println(three); three = three*=one; System.out.println(three); three = three/=one; System.out.println(three); three = three%=one; System.out.println(three);
在同一个方法内每个变量只能定义一次,但是可以给变量赋值多次,每次赋值都会把以前这个变量的值覆盖掉。
比如 int one =10;前面这个 int 表示 定义了一个变量 , one 表示这个变量名字叫 one
而这个 10 表示 把整数 10 赋值给 名叫 one 的变量,它们的顺序是:1.先定义一个变量,2. 变量名设置为 one
,3.把 10 赋值给 one。可能我的说法不太对,但是意思是这么个意思。
你会出错,是因为你名叫 three 的变量每一次赋值时你都在前面加了 int ,刚好违反了在同一个方法内每个变量
只能定义一次的规定。把除了第一个以外 名叫three的变量前的int去掉就行了 (^.^)。
int one = 10 ;
int two = 20 ;
int three = 0 ;
int 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%);
- -
还是不对啊
Java入门第一季(IDEA工具)升级版
1165172 学习 · 17581 问题
相似问题