![]() Using - operator with char data and int number ("Result of Subtraction of a="+a+" and b = "+b+" is "+(a-b)) Using - operator with float and int number The statements below demonstrate two different ways to use - operator with the operands. Moreover, When - operator is used as a unary operator, it negates the numeric value of a variable. However, if the two operands are of different datatypes, implicit datatype promotion occurs in such a way that the value of lower datatype is promoted to the higher datatype. When we use - with char type data, it takes the ASCII value of that char and operates on same. We can use - operator with any numeric type as well as char type. In Java, subtraction operator " -" is used as either a unary operator or a binary operator. Output Result of Addition of a=10.5 and b = 20 is 30.5Īdding numeric value 20 to char value A : Result is 85 Using + operator to concatenate two strings ("Adding numeric value "+b+" to char value "+c+" : Result is "+(b+c)) Using + operator with char data and int number ("Result of Addition of a="+a+" and b = "+b+" is "+(a+b)) Using + operator with float and int number The statements below demonstrate the " +" operator with the operands. ![]() Hence, it returns either a numeric value or a string. Moreover, when we use it with string objects, it concatenate two strings. When we use + with char type data, it takes the ASCII value of that char and operates on same. We can use + operator with any numeric type as well as char type. In Java, addition operator " +" is used as a binary operator. Left_operand arithmetic_operator right_operandĮxamples of different Arithmetic Operators in Java 1.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |