Материал готовится,

пожалуйста, возвращайтесь позднее

пожалуйста, возвращайтесь позднее

Understanding operators

Every programming language supports operators, characters or sets of characters that execute particular operation. Java remember is C-style language and it uses the same set of operators as most such languages. If you already know JavaScript or ActionScript you will find that the operators in Java are almost identical. Here are some of the types of operators I'll discuss in this video. Assignment operators let you set values. There is a Simple Assignment Operator and then there were more Complex Assignment Operators that let you assignment and math in a single statement.

There are equality and relational operators that let you compare values to each other. There are mathematical operators that let you execute common mathematical process, Conditional operators that let you define complex conditional processes, and the ternary operator which is a special operator I'll describe in a later video when I discuss conditional processing. The most common operator that you'll find yourself using is the Assignment operator. The single equals character is the assignment operator. You put the variable you're assigning to on the left and the value on the right.

You can assign a literal value or a value return from a method or a reference to a complex object. Regardless of what you're assigning the single equals operator always is used. The simple math operators are the same as in JavaScript and ActionScript, the plus operators is used for math. So if I start with the value of 10 and I increment it by 5 with the + operator I get a value of 15, the - character is the traditional minus operator, the asterisk is used for multiplication and the forward slash is division.

There is another single character operator worth knowing about the modulus or remainder operator. Java uses the % character for this. If you take a value of 10 and you take the modulus of 5 that returns a reminder of 0. So those are the five primary math operators. You can combine these math operators with assignment too. Once again starting with an initial value of 10, let's take look at how you can increment and decrement values. The ++; operator means add one, so adding 1 to 10 gives you 11, the - -; operator goes in the other direction decrementing by one and that would give you a result of 9.

Here is how you can combine math operators with assignment, += means take the current value of this variable and add whatever is on the right side. So intValue +=5; would be 15. intValue -=5; would be 5, *= 5; equals 50 and /= 5; would result an intValue having a value of 2. Be aware that when you use the /= you need to make sure that you're assigning a value that matches the data type of the original variable.

When you use the increment and decrement operators you can place them either before or after the variable name, the operational result will be a little bit different depending on the position of the operator. Once again starting with the value of 10, a Postfix operator looks like this intValue ++, when you place the ++ operator after the variable you're saying first evaluate the variable and then execute the mathematical operation, because I've wrapped this inside a print line command I'm going to be outputting a value and changing it's value, but you need to know that with this Postfix syntax the evaluation happens first and only after that does the math happen.

The result would be an output of 10, but then after the statement is complete the new value of the variable would be 11.

Every programming language supports operators, characters or sets of characters that execute particular operation. Java remember is C-style language and it uses the same set of operators as most such languages. If you already know JavaScript or ActionScript you will find that the operators in Java are almost identical. Here are some of the types of operators I'll discuss in this video. Assignment operators let you set values. There is a Simple Assignment Operator and then there were more Complex Assignment Operators that let you assignment and math in a single statement.

There are equality and relational operators that let you compare values to each other. There are mathematical operators that let you execute common mathematical process, Conditional operators that let you define complex conditional processes, and the ternary operator which is a special operator I'll describe in a later video when I discuss conditional processing. The most common operator that you'll find yourself using is the Assignment operator. The single equals character is the assignment operator. You put the variable you're assigning to on the left and the value on the right.

You can assign a literal value or a value return from a method or a reference to a complex object. Regardless of what you're assigning the single equals operator always is used. The simple math operators are the same as in JavaScript and ActionScript, the plus operators is used for math. So if I start with the value of 10 and I increment it by 5 with the + operator I get a value of 15, the - character is the traditional minus operator, the asterisk is used for multiplication and the forward slash is division.

There is another single character operator worth knowing about the modulus or remainder operator. Java uses the % character for this. If you take a value of 10 and you take the modulus of 5 that returns a reminder of 0. So those are the five primary math operators. You can combine these math operators with assignment too. Once again starting with an initial value of 10, let's take look at how you can increment and decrement values. The ++; operator means add one, so adding 1 to 10 gives you 11, the - -; operator goes in the other direction decrementing by one and that would give you a result of 9.

Here is how you can combine math operators with assignment, += means take the current value of this variable and add whatever is on the right side. So intValue +=5; would be 15. intValue -=5; would be 5, *= 5; equals 50 and /= 5; would result an intValue having a value of 2. Be aware that when you use the /= you need to make sure that you're assigning a value that matches the data type of the original variable.

When you use the increment and decrement operators you can place them either before or after the variable name, the operational result will be a little bit different depending on the position of the operator. Once again starting with the value of 10, a Postfix operator looks like this intValue ++, when you place the ++ operator after the variable you're saying first evaluate the variable and then execute the mathematical operation, because I've wrapped this inside a print line command I'm going to be outputting a value and changing it's value, but you need to know that with this Postfix syntax the evaluation happens first and only after that does the math happen.

The result would be an output of 10, but then after the statement is complete the new value of the variable would be 11.

Загрузка...

Выбрать следующее задание

Ты добавил

Выбрать следующее задание

Ты добавил