Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


puja sen
operators
1 Answer(s)      2 years and 9 months ago
Posted in : Java Interview Questions


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


Advertisement
View Answers

March 7, 2012 at 3:27 PM


answer should be i =4 , k = 10

first know the difference between post increment and pre increment. if u dont know,pls refer the google.

Below i mentioned the reason.

it must evaluate right to left.

according to yr code + i == this one wont execute first. because left side variable or value not available. (for ex a+ i or 5+i) so its move next and execute ++i , then it calculate 3 after that i++ should work, that value is also 3. then add the 3+3 +4 = 10.

I hope u understood what i am trying to say. if not plz let me know.



Related Tutorials/Questions & Answers:
Operators
Operators       Operators are symbols that performs some operations on one or more then one operands. Once we declare and initialize variables, we can use operators to perform
Operators
Operators       Operators are symbols that performs some operations on one or more then one operands. Once we declare and initialize variables, we can use operators to perform
Advertisements
ciruit operators.
ciruit operators.  Explain the benefit of short ciruit operators
Java operators
Java operators  What is the difference between the >> and >>> operators
Operators
Operators       Operators are symbols that performs some operations on one or more then one operands. Once we declare and initialize variables, we can use operators to perform
Operators
Operators       Operators are symbols that performs some operations on one or more than one operands. Once we declare and initialize variables, we can use operators to perform
bitwise operators
bitwise operators  Write short note on bitwise operators of Java.   Please visit the following links: http://www.roseindia.net/java/java-tips/data/expressions/slides-bitops.shtml http://www.roseindia.net/java/java
logical operators in objective c
logical operators in objective c  logical operators in objective c
boolean operators in JavaScript
boolean operators in JavaScript  What boolean operators does JavaScript support
SQL AND Operators
SQL AND Operators       The AND operator displays records if both conditions are true. 1st Condition 2nd Condition Result false
SQL OR Operators
SQL OR Operators       The OR operator displays records if any of the conditions is true. 1st Condition 2nd Condition Result false
Bitwise Operators in java 7
In this section you will learn about the Bitwise Operators. This is one type of operators
Arithmetic Operators in java 7
In this section you will learn about the Arithmetic operators. This is one type of operators
Unary Operators in java 7
In this section you will learn about the Unary operators. This is one type of operators
What is the difference between the >> and >>> operators?
What is the difference between the >> and >>> operators?   hi, What is the difference between the >> and >>> operators? Thanks
PHP Operators
3.5. PHP Operators Operators are used for performing specific tasks. The operators in PHP are same like other programming languages like Arithmetic operators, Assignment Operators, Comparison Operators, and logical operators. 3.5.1.
PHP Operators
Operators in PHP: Every computer language has its own set of operators, most of the operators are same among all languages and  few languages supports some different set of operators. PHP supports mainly three kind of operators
difference between == and === operators?
difference between == and === operators?  Is (====) operator available in java or not? difference between
precedence operators c++ example
precedence operators c++ example  What is the precedence of operators in c++ and how does it works?   This might be helpful.. Operator precedence
Operators and Expressions
Operators and Expressions       Operators: Operators are such symbols that perform some operations on one or more operands. Operators are used to manipulate primitive data
Operators In Java
Operators In Java In this section we will read about operators in Java. We will illustrate the use of operators in Java using a simple example. Java provides various operators to manipulate the operations in Java. Operators
Operators in java 7
This tutorial describes the concept of operators in java 7
left shift and rigth shift operators
left shift and rigth shift operators   hi some programs for left shift and right shift operators
Arithmetic Operators
Arithmetic Operators Operator is used to perform operation on variable and values. Arithmetic Operators is used to perform arithmetic operations(like... the list of available arithmetic operators : OPERATOR WORK USE
php Operators
php Operators:       Operators are one of the important feature of every language. In php operators... Operator Execution Operators Array Operators Type Operators 1.  
right and left shift operators
right and left shift operators   hi i am jane pls explain the differentiate between right shift and left shift operators   The Left Shift "<<" operator shifts the left operand to the left side
Other Operators in java 7
Other Operators in java 7 In this section you will learn about the Other Operators. This is one type of operators. Conditional Operator (? :): This is also called ternary operator. It contains three operand and two operators
Relational Operators in java 7
Relational Operators in java 7 In this section you will learn about the Equality and Relational operators. This is one type of operators. Equality and Relational Operators : Equality operator checks for equality of operands
Advertisements
 

 

 

DMCA.com