java程序员个人能力介绍
Java Operators Aptitude Questions and Answers: This section provides you Java Operators related Aptitude Questions and Answers with multiple choices. Here, You will get solution and explanation of each question.
Java操作员能力倾向问题和解答 : 本部分为您提供了与Java操作员有关的能力倾向问题和解答的多种选择。 在这里,您将获得每个问题的解决方案和解释。
Java操作员能力倾向问题列表 (List of Java Operators Aptitude Questions and Answers)
class Opr
{
public static void main(String args[])
{
boolean ans=false;
if(ans=true)
System.out.print("Done");
else
System.out.print("Fail");
}
}
Correct Answer: 1
Done
in condition ans=true, the value of ans becomes true hence condition is true.
class Opr
{
public static void main(String args[])
{
int x=5,y;
y= ++x + x++ + --x;
System.out.println(x + "," + y);
}
}
Correct Answer: 2
6, 18
In JAVA ++/-- operators evaluates with expression Rule to evaluate expression with ++/-- : [pre_increment -> expression ->post_increment] Consider the expression,
y=++x + x++ + --x; => y=6 + 6 + 6;
here, ++x evaluates first, value of x will be 6, x++ evaluates after adding starting two terms ++x + x++ [6+6], and then x will be 7 (due to x++), --x will evaluate before adding value in previous result, so expression will solve like 6+6+6.
正确答案:2
6、18
在JAVA中,+ /-+ /-运算符使用表达式Rule来评估++ /-: [pre_increment-> expression-> post_increment]考虑表达式,
y = ++ x + x ++ + --x; => y = 6 + 6 + 6;
在这里,++ x首先求值,x的值为6,x ++在加上两个开始项之后求值++ x + x ++ [6 + 6],然后x将为7(由于x ++),--x将求值在之前的结果中添加值之前,表达式将像6 + 6 + 6一样求解。
class Opr
{
public static void main(String args[])
{
byte a,b;
a=10; b=20;
b=assign(a);
System.out.println(a +","+ b);
}
public static byte assign(byte a)
{
a+=100;
return a;
}
}
Correct Answer: 2
10, 110
Here variable a in main and a in assign are different, only value of a (10) will pass into function assign, value of a will remain same, answer will 10, 110.
正确答案:2
10、110
这里变量a in和main的赋值是不同的,只有a的值(10)会传递给函数assign,a的值将保持不变,答案将为10、110。
class Opr
{
public static void main(String args[])
{
int a,b,result;
a=10; b=20;
result=(b>=a);
System.out.print(result);
}
}
Correct Answer: 1
ERROR: incompatible types.
Consider the expression result=(b>=a); here value of b is largest from a, True will return, and true (boolean) can not assign into integer variable.
正确答案:1
错误:不兼容的类型。
考虑表达式result =(b> = a) ; 此处b的值是a的最大值,True将返回,并且true(布尔)不能分配给整数变量。
class Opr
{
public static void main(String args[])
{
int a,b,result;
a=10; b=20;
result=(int)(b>=a);
System.out.print(result);
}
}
Correct Answer: 1
ERROR: incompatible types.
Consider the expression result=(int)(b>=a); .boolean is not convertible to int.
翻译自: https://www.includehelp.com/java-aptitude/java-aptitude-operators-questions-and-answers.aspx
java程序员个人能力介绍