Java需要帮助来理解代码 [英] Java need help to understand the code
本文介绍了Java需要帮助来理解代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
公共课考试{
int i;
int j;
public static void main(String [] args){
测试t1 =新测试();
测试t2 =新测试();
t1.j = t2.i = 5;
t1.i = t2.j = 6;
System.out.print(t1.j ++ ++ t2.i--);
}
}
解决方案
因为x ++是所谓的后缀运算符:它意味着获取x的值然后增加x一个但不影响你之前提取的值:
int temp = x;
x = x + 1 ;
return temp;
参见 https://docs.oracle.com/javase/tutorial/java/index.html [ ^ ],并通过它完成所有答案。
public class Test {
int i;
int j;
public static void main(String[] args) {
Test t1 = new Test();
Test t2 = new Test();
t1.j=t2.i=5;
t1.i=t2.j=6;
System.out.print(t1.j++ + " " + t2.i--);
}
}
解决方案
Because x++ is what's called a "postfix" operator: it means "get the value of x and then increase x by one but do not affect the value you fetched earlier":
int temp = x; x = x + 1; return temp;
See https://docs.oracle.com/javase/tutorial/java/index.html[^], and work through it, all the answers can be found there.
这篇关于Java需要帮助来理解代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文