Your SlideShare is downloading.
×

×
Saving this for later?
Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime – even offline.

Text the download link to your phone

Standard text messaging rates apply

Like this presentation? Why not share!

- Operators and Expressions by Viel Joy Piston 283 views
- Operators and expressions by vishaljot_kaur 863 views
- Operators in C++ by Sachin Sharma 3026 views
- Operators and Expression by shubham_jangid 1164 views
- Operator & Expression in c++ by bajiajugal 5649 views
- Data types in java by sonybabu 14161 views
- Data types by Nokesh Prabhakar 1784 views
- Control structures in Java by Ravi_Kant_Sahu 8135 views
- Memory Management C++ (Peeling oper... by Sameer Rathoud 1827 views
- operator overloading in C++ by baabtra.com - Fir... 444 views
- Unit 2 Java by arnold 7490 2195 views
- 06. operator overloading by Haresh Jaiswal 159 views

1,727

Published on

No Downloads

Total Views

1,727

On Slideshare

0

From Embeds

0

Number of Embeds

0

Shares

0

Downloads

55

Comments

0

Likes

1

No embeds

No notes for slide

- 1. - Ankita KariaAnkita R Karia 1 February 2012 1
- 2. JAVA operators can be classified into a number of related categories as below:- Arithmetic. + - * / % Relational. < <= > >= == != && || ! Logical. AND OR NOT T && T = T F || F= F T=F F=T Ankita R Karia 1 February 2012 2
- 3. ASSIGNMENT CONDITIONAL INCREMENT = ? : ++• Is used to exp1 ? exp2 : exp3 •PRE:- Firstassign value to e.g.:- x=(a>b)?a:b subtracts 1 from operand and then thevariable. result is assigned .e.g.:- a =10 DECREMENT - - ++m;•SHORTHAND a=a+1 • PRE:- First subtracts 1 •POST:- First assigns the value toCan also be from operand and then the the variable on left and result is assigned .written as - - m; then decrements a+=1 operand •POST:- First assigns the m++a = a / (n+1) value to the variable on left and then decrements operand m-- Ankita R Karia 1 February 2012 3
- 4. JAVA permits mixing of constants and variables of different types in an expression, but during evaluation it adheres to very strict rules of type conversion. If operands are of different types, the “lower” type is automatically converted to “higher” type before the operation proceeds. The result is of higher type. The final result of an expression is converted to the type of the variable on the left of the assignment before assigning the value Ankita R Karia 1 February 2012 4
- 5. EXAMPLES ACTIONx= (int) 7.5 7.5 is converted to integer by truncationa = (int)21.3/(int)4.5 Evaluated as 21/4 and the result would be 5b = (double) sum/n Division is done in floating point modey = (int) (a+b) The result of a+b is converted to integery = (int) a+b a is converted to integer and then added to bp = cost ((double)x) Converts x to double before using it as parameter Ankita R Karia 1 February 2012 5
- 6. JAVA supports basic math functions through Math class defined in the java.lang.package. The functions should be used as follows:- Math.function_name(); java.lang.Math Example: y = Math.sqrt(x); Function name Ankita R Karia 1 February 2012 6
- 7. FUNCTIONS ACTION sin(x) Returns the sine of the angle x in radians cos(x) Returns the cosine of the angle x in radians tan(x) Returns the tangent of the angle x in radians asin(x) Returns the angle whose sine is y atan2(x,y) Returns the angle whose tangent is x/y pow(x,y) Returns xy exp(x) Returns ex log(x) Returns the natural logarithm of x sqrt(x) Returns square root of x abs(x) Returns absolute of x max(a,b) Returns maximum of1 a and b Ankita R Karia February 2012 7
- 8. Determine the value of the following arithmetic expression. (a=5,b=2,c=1)1. m = ++a*5;2. p*=x/y; x=10,y=2,p=2;3. s/=5; s=5;4. n=b++-c*2; Ankita R Karia 1 February 2012 8
- 9. Ankita R Karia 1 February 2012 9
- 10. Ankita R Karia 1 February 2012 10
- 11. Determine the value of the following logical expression. (a=5,b=10,c=-6)1. a<b && a<c;2. a<b && a>c;3. a= = c || b>a;4. b>15 && c<0 || a>0;5. (a/2.0==0.0&&b/2.0!=0.0)||c<0.0 Ankita R Karia 1 February 2012 11
- 12. Ankita R Karia 1 February 2012 12
- 13. 1. The straight-line method of computing the yearly depreciation of the value of an item is given by depreciation = Purchase Price – Salvage Value Years of service Write a program to determine the salvage value of an item when the purchase price, years of service and Annual depreciation are given Ankita R Karia 1 February 2012 13

Be the first to comment