Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我写了一个打印方法,告诉用户祝贺他们,但同时我有另一个名为下载的字段,我想在调用 thr 打印方法后更新字段下载,谢谢,我正在使用 bluej
代替
int num; this.noOdDownloads = num; this.noOdDownloads = num + 1;
做
this.noOdDownloads++;
你的原始程序有两个问题:1)num没有实例化,这是编译器会抱怨的,2)即使你实例化了它,比如 with int num=0;, num实际上是方法中的局部变量。每次运行该方法时,都会再次实例化局部变量并重置为0. 然后,当您将其值分配给 时noOdDownloads,后者也将重置为0。
num
int num=0;
0
noOdDownloads