• Home
  • Courses
  • School
  • Programs
  • Problems
  • Contact Us
  • My account
  • Register

Have any question?

(+91) 98222 16647
info@simplycoding.in
RegisterLogin
Simply Coding
  • Home
  • Courses
  • School
  • Programs
  • Problems
  • Contact Us
  • My account
  • Register

Java

Java Operators and Operator precedence questions

  • Categories Java, Java Operators, Operators

Today we are going to practice questions on Java Operators and its precedence. Before you attempt the questions, do a quick review of these two topics by going through our video link here.

    1.  Java Operators 
    2. Java Operator Precedence and Associativity
 
  1. Name the type of operators listed below (assignment, relational, logical etc):
    1. <
    2. ++
    3. &&
    4. ?:

    Ans.

    1. Relational Operator
    2. Arithmetic Operator (Increment, unary)
    3. Logical operator (and)
    4. Ternary operator
  1. Name the type of operators listed below (assignment, relational, logical etc):
    1. !
    2. ==
    3. %
    4. =

Ans.

    1.  Logical Operator
    2. Relational Operator
    3. Arithmetic Operator (Modulus)
    4. Assignment operator
  1. Operators with higher precedence are evaluated before operators with relatively lower precedence. Arrange the operators given below in order of higher precedence to lower precedence.

(i) &&        (ii) %        (iii) >=         (iv) ++       

Ans. 

(i) ++          (ii)  %            (iii)  >=          (iv)  &&

  1. Arrange the operators given below in order of higher precedence to lower precedence.

(i) ()          (ii) ?:         (iii) ==           (iv) | |       

Ans. 

(i) ()            (ii)  ==          (iii)  | |            (iv)  ?:

  1. Arrange the operators given below in order of higher precedence to lower precedence.

(i) +         (ii) &&        (iii) !=          (iv) ++ 

Ans. 

(i) ++         (ii) +         (iii)  !=          (iv)  &&

  1. What will be the output of the following. if x=5 initially?

(i)  5 * ++x
(ii) 5 * x++

Ans:

(i) 30

(ii) 25

  1. What is the result stored in x, after evaluating the following expression?
int x = 5;
x = x++ * 2 + 3 * –x;

Ans.

x=-8

  1. Give the output of this code
int a = 9;
a++;
System.out.println (a);
a -= a – - – a;
System .out.println (a);

Ans:

10
8

Explanation

a = 9;
a++; // a = 10
SOP (a) // Prints 10
a -= a – - – a;
a = 10 – (10 – 8)
a = 10 -2 = 8
SOP (a) // Prints 8
  1. Evaluate the following expression: when a=10, b=8 

i) ++a-b–                   ii) a%b++
iii) a*=b+5               iv) x=69>>>2

Ans

(i) 3                   (ii) 2               (iii)  130                  (iv)  17

  1. If m=5 and n=2 output the values of m and n after execution in (i) and (ii).

(i)   m -= n;
(ii)  n = m + m/n;   

Ans:

(i) the value of m is 3 and n is 2
(ii) The value of m is 5 and n is 7

  1. What will be the output of the following code?
int k = 5, j = 9;
k += k++ – ++j + k;
System.out.println(“k=” +k);
System.out.println(“j=” +j);

Ans.

k= 6       

j= 10

  1. What is the value of y after evaluating the expression given below
    y+=++y + y– + –y; when int y=8.

Ans.

y=33

  1. Give the output of the following expression:
    a+=a++ + ++a + –a + a–; when a=7.

Ans.

a=39

  1. If int y=10 then find y and z after executing this statement:

int z=(++y * (y++ +5));

Ans.

y=12           z=176

  1. What will be the result stored in x after evaluating the following expression?
int x=4;
x += (x++) + (++x) + x;

Ans.

x=20

  1. What is the value of y after evaluating the expression given below?
    y += ++y + y– + –y; when int y = 8.

Ans:

y = 8 + 9 + 9 + 7
y = 33

  1. What is the value of x1 if x=5 ?

x1=++x – x++ + –x

Ans.

x1= ++x – x++ + –x
x1= 6 (x is incremented to 6) – 6 (x is incremented to 7) + 6 (x is decremented to 6)
= 6

  1. Give the output of the following expression :
    a+=a++ + ++a + -–a + a-– ; when a = 7

Ans.

a+=a++ + ++a + –-a + a–- ;
a = 7 + (a++ + ++a + -–a + a–-);
a = 7 + (7 + 9 + 8 + 8);
a = 39
  1. If int y = 10 then find int z = (++y * (y++ + 5));

Ans.

Increment operator has the highest precedence. So, ++y and y++ will be evaluated starting from left.

In ++y, the value of y will be incremented to 11 and then 11 will be used in the expression.

When y++ is evaluated, the current value of y i.e. 11 will be used and then y will be incremented from 11 to 12.

int z = (++y * (y++ + 5));
= 11 * (11 + 5 )
= 11 * 16
= 176
  • Share:
author avatar
Simply Coding

Previous post

Crack Java Math Problems
June 10, 2020

Next post

Java if else & switch Practice Questions
June 10, 2020

You may also like

Java Operator
Java Operators
16 June, 2021
Java Class Librares
Java Class Libraries and Packages
16 June, 2021
Crack Java Math Problems
Forming Math Expressions
13 June, 2020

Leave A Reply Cancel reply

You must be logged in to post a comment.

Categories

  • Uncategorized
  • Programs
    • Python
    • Java
  • Problems
    • Python
    • Java
    • Web Development
      • Internet
    • Emerging Technologies
  • Notes
    • General
    • QBasic
    • MS Access
    • Web Development
      • XML
      • HTML
      • JavaScript
      • Internet
    • Database
    • Logo Programming
    • Scratch
    • Emerging Trends
      • Artificial Intelligence
      • Internet of Things
      • Cloud Computing
      • Machine Learning
    • Computer Fundamentals
      • Computer Networks
      • E-Services
      • Computer Hardware
    • Python
    • Java
  • School
    • ICSE
      • Computers Class 9
        • Java Introduction
        • Tokens & Data Types
        • Java Operators
        • Math Library
        • if & switch
        • For & While
        • Nested loops
      • Computer Class 10
        • Sample Papers
        • OOPS concepts
        • Functions in Java
        • Constructors
        • Arrays in Java
        • Strings in Java
    • SSC
      • IT Class 11
        • IT Basics
        • DBMS
        • Web Designing
        • Cyber Laws
      • IT Class 12
        • Web Designing
        • SEO
        • Advanced JavaScript
        • Emerging Tech
        • Server Side Scripting
        • E-Com & E-Gov
      • Computer Science 11
      • Computer Science 12
    • CBSE
      • Computer 9
        • Basics of IT
        • Cyber Safety
        • Scratch
        • Python
      • Computer 10
        • Sample Papers
        • Networking
        • HTML
        • Cyber Ethics
        • Scratch
        • Python
      • Computer Science 11
        • Computer Systems
        • Python 11
          • Python Basics
          • Python Tokens
          • Python Operators
          • Python if-else
          • Python loops
          • Python Strings
          • Python List
          • Python Tuple
          • Python Dictionary
          • Python Modules
        • Data Management
      • Computer Science 12
        • Sample Papers
        • Python 12
          • Python Functions
          • Python File Handling
          • Python Libraries
          • Python Recursion
          • Data Structures
        • Computer Networks
        • Data Management
    • ISC
      • Computer Science 11
        • Introduction to Java
        • Values & Data Types
        • Operators
        • if & switch
        • Iterative Statements
        • Functions
        • Arrays
        • String
        • Data Structures
        • Cyber Ethics
      • Computer Science 12
        • Sample Papers
        • Boolean Algebra
        • OOPS
        • Wrapper Classes
        • Functions
        • Arrays
        • String

Categories

  • Uncategorized
  • Programs
    • Python
    • Java
  • Problems
    • Python
    • Java
    • Web Development
      • Internet
    • Emerging Technologies
  • Notes
    • General
    • QBasic
    • MS Access
    • Web Development
      • XML
      • HTML
      • JavaScript
      • Internet
    • Database
    • Logo Programming
    • Scratch
    • Emerging Trends
      • Artificial Intelligence
      • Internet of Things
      • Cloud Computing
      • Machine Learning
    • Computer Fundamentals
      • Computer Networks
      • E-Services
      • Computer Hardware
    • Python
    • Java
  • School
    • ICSE
      • Computers Class 9
        • Java Introduction
        • Tokens & Data Types
        • Java Operators
        • Math Library
        • if & switch
        • For & While
        • Nested loops
      • Computer Class 10
        • Sample Papers
        • OOPS concepts
        • Functions in Java
        • Constructors
        • Arrays in Java
        • Strings in Java
    • SSC
      • IT Class 11
        • IT Basics
        • DBMS
        • Web Designing
        • Cyber Laws
      • IT Class 12
        • Web Designing
        • SEO
        • Advanced JavaScript
        • Emerging Tech
        • Server Side Scripting
        • E-Com & E-Gov
      • Computer Science 11
      • Computer Science 12
    • CBSE
      • Computer 9
        • Basics of IT
        • Cyber Safety
        • Scratch
        • Python
      • Computer 10
        • Sample Papers
        • Networking
        • HTML
        • Cyber Ethics
        • Scratch
        • Python
      • Computer Science 11
        • Computer Systems
        • Python 11
          • Python Basics
          • Python Tokens
          • Python Operators
          • Python if-else
          • Python loops
          • Python Strings
          • Python List
          • Python Tuple
          • Python Dictionary
          • Python Modules
        • Data Management
      • Computer Science 12
        • Sample Papers
        • Python 12
          • Python Functions
          • Python File Handling
          • Python Libraries
          • Python Recursion
          • Data Structures
        • Computer Networks
        • Data Management
    • ISC
      • Computer Science 11
        • Introduction to Java
        • Values & Data Types
        • Operators
        • if & switch
        • Iterative Statements
        • Functions
        • Arrays
        • String
        • Data Structures
        • Cyber Ethics
      • Computer Science 12
        • Sample Papers
        • Boolean Algebra
        • OOPS
        • Wrapper Classes
        • Functions
        • Arrays
        • String
Simply Coding Computer Courses for School                Privacy Policy     Terms of Use     Contact Us

© 2021 Simply Coding

Login with your site account

Lost your password?

Not a member yet? Register now

Register a new account

Are you a member? Login now