Search Placementyogi.com
 

Java Operators Objective Questions and Answers

  :: Topics ::

1

What is the output of the following program?

class Operators1 
{
	public static void main(String[] args) 
	{
		int i=0;
		System.out.println(i++);
		System.out.println(i);
		System.out.println(++i);
	}
}
A.

0 0 1

B.

0 1 2

C.

1 1 1

D.

1 1 2

E.

Compilation Error

See Answer & Explanation Lets Discuss
Correct answer is : B
Explanation

Post-increment operator increases the value of the operand after its current usage . Hence 0 is printed in the first print statement as the value of i is still 0, but prints 1 in the next line as the value of i has incremented by this time. In the 3rd print statement, i is incremented before usage and hence the incremented value is printed.

 
2

What is the output of the following program?

class Operators2 
{
	public static void main(String[] args) 
	{
		int i=0;
		System.out.println(i--);
		System.out.println(i);
		System.out.println(--i);
	}
}
A.

0 0 -1

B.

0 -1 -2

C.

-1 -1 -2

D.

-1 -1 -1

E.

Compilation Error

See Answer & Explanation Lets Discuss
Correct answer is : B
Explanation

In case of post decrement, the decremented value comes in to picture only in the next usage. So,

1st print statement prints 0 as the i is decremented after the usage.

2nd print statement prints -1 i.e. the decremented value.

3rd statement has pre decrement operator and hence prints -2 i.e. the decremented value.

 
3

What is the output of the following program?

class Operators1 
{
	public static void main(String[] args) 
	{
		int i=0;
		System.out.println("i--="+i--+" , --i="+ --i);
	}
}
A.

i-- = 0, --i=-2

B.

i-- = -1, --i= -1

C.

i-- = -1, --i =-2

D.

None of the Above

See Answer & Explanation Lets Discuss
Correct answer is : A
Explanation

Since, in the case of post decrement, the decremented value becomes available only in the next use, the first i-- prints the current value i.e. 0 and the value of i becomes -1, when --i is encountered later the current value of i was -1 and it is decremented again and i becomes -2 Hence -2 is printed

 
4

What is the output of the following program?

class ModulusOperators1 
{
	public static void main(String[] args) 
	{
		float f=7.5f;
		System.out.println("7.5 % 2 ="+ f%2);
	}
}
A.

1

B.

Compilation Error: Modulus operator can not be applied on Floating Point Numbers

C.

1.5

D.

None of the Above

See Answer & Explanation Lets Discuss
Correct answer is : C
Explanation

Java supports modulus operators on Floating Point Numbers too. This is opposite to C Language where you can not apply Modulus operator on Floating Point Numbers.

 
5

What is the output of the following program?

class ModulusOperators1 
{
	public static void main(String[] args) 
	{
		System.out.println("-8%3="+ -8%3);
		System.out.println("10%-3="+ 10%-3);
		System.out.println("-7%-3="+ -7%-3);
	}
}
A.

2 -1 -1

B.

-2 -1 1

C.

-2 1 -1

D.

-2 1 1

See Answer & Explanation Lets Discuss
Correct answer is : C
Explanation

The sign of remainder is always same as the sign of the dividend in Java.

 
 

Banner to LogicGuns.com

Hide Page Information

Multiple Choice Questions on Operators in Java ?

In this section you can learn and practice Java Objective Questions based on "Operators in Java " and improve your skills in order to face the interview and appear for Java certification (SCJP/ OCJP)

Where can I get Java Programming Operators questions and answers with explanation?

Placementyogi provides you lots of fully solved Java Programming (Operators and Assignments) questions and answers with Explanation. Solved examples with detailed answer description, explanation are given and it would be easy to understand. All students, freshers can download Java Operators quiz questions with answers as PDF files and eBooks.

Where can I get Java Programming Operators Interview Questions and Answers (objective type, multiple choice)?

Here you can find objective type Java Programming Operators questions and answers for interview and entrance examination. Multiple choice and true or false type questions are also provided.

How to solve Java Operators problems?

You can easily solve all kind of Java questions based on Operators by practicing the objective type exercises given below, also get shortcut methods to solve Java Programming Operators and Assignments problems.