Difference between revisions of "Java/C2/Arithmetic-Operations/English-timed"

From Script | Spoken-Tutorial
Jump to: navigation, search
 
(12 intermediate revisions by 6 users not shown)
Line 1: Line 1:
 
  {| border=1
 
  {| border=1
|| '''Time''''
+
|| '''Time'''
 
|| '''Narration'''
 
|| '''Narration'''
 
  
 
|-
 
|-
 
|  00:01
 
|  00:01
|  Welcome to the  tutorial on '''Arithmetic Operations in Java'''.
+
|  Welcome to the  tutorial on '''Arithmetic Operations''' in Java.
  
 
|-
 
|-
|  00:06
+
|  00:05
| In this tutorial, you will learn about the various   '''Arithmetic Operations ''' namely
+
| In this tutorial, you will learn about the various '''Arithmetic Operators''' namely
 
'''Addition'''
 
'''Addition'''
  
Line 19: Line 18:
 
'''Division''' and  
 
'''Division''' and  
  
'''How to use them.'''
+
How to use them.
  
 
|-
 
|-
 
|  00:16
 
|  00:16
|  For this tutorial we are using  
+
|  For this tutorial, we are using:
  
 
'''Ubuntu 11.10''',
 
'''Ubuntu 11.10''',
Line 29: Line 28:
 
'''JDK 1.6''' and  
 
'''JDK 1.6''' and  
  
'''Eclipse 3.7'''.
+
'''Eclipse 3.7'''
 +
 
 
|-
 
|-
 
|  00:24
 
|  00:24
|  To follow this tutorial you must have eclipse installed on your system
+
|  To follow this tutorial, you must have '''eclipse''' installed on your system
  
 
|-
 
|-
 
|  00:28
 
|  00:28
|  and you must '''know how to create, save and run a file in Eclipse'''.
+
|  and you must know how to '''create, save''' and '''run''' a file in '''Eclipse'''.
 
+
  
 
|-
 
|-
|  00:33 
+
|  00:32
| If not, for relevant tutorial please visit our website as shown.
+
| If not, for relevant tutorials, please visit our website as shown.
  
 
|-
 
|-
|  00:43
+
|  00:42
 
|  Here is a list of operators and the mathematical operations they perform
 
|  Here is a list of operators and the mathematical operations they perform
 
+
plus (+) symbol for addition
 
+
minus (-) for subtraction
* plus symbol for addition
+
asterisk (*) for multiplication
* minus for subtraction
+
and slash (/) for division
* asterisk for multiplication
+
* front slash for division
+
  
 
|-
 
|-
|  00:55
+
|  00:54
 
| We shall look at each of them in detail.
 
| We shall look at each of them in detail.
  
 
|-
 
|-
 
|  01:05
 
|  01:05
| Here We have Eclipse IDE and the skeleton required for the rest of the code.  
+
| Here we have the 'Eclipse IDE' and the skeleton required for the rest of the code.  
 
+
  
 
|-
 
|-
|  01:11
+
|  01:10
| We have created a class by name '''Arithmetic Operations''' and added the '''main '''method.
+
| We have created a '''class''' by name '''ArithmeticOperations''' and added the '''main method'''.
 
+
  
 
|-
 
|-
Line 76: Line 71:
  
 
|-
 
|-
|  01:27
+
|  01:26
| '''int y = 10;'' print result
+
| '''int y = 10;'''
 
+
'''int result;'''
  
 
|-
 
|-
 
|  01:35
 
|  01:35
| '''x''' and '''y''' will be the operands  and the  '''result''' will store the output of operations.
+
| 'x' and 'y' will be operands  and the  '''result''' will store the output of the operations.
  
 
|-
 
|-
|  01:42
+
|  01:41
|   Let us add them and print the result.''' Result= x+y;''' system. out. println ''''in parantesis '''result''
+
| Let us add them and print the result. '''result= x+y;''' '''system. out. println''' in parentheses '''result'''.
 
   
 
   
 
 
 
 
|-
 
|-
 
| 02:10
 
| 02:10
|  Save it with ''Control S'' and ''control F11'' to''' Run'''
+
'''Save''' it with '''Control S''' and '''control F11''' to '''Run'''.
 
+
 
+
  
 
|-
 
|-
 
| 02:17
 
| 02:17
|   We see, that the output of addition is stored and the value has been printed
+
| We see that the output of the addition has been stored in '''result''' and the value has been printed.
 
+
 
|-
 
|-
|  02:25
+
|  02:24
|  Now Let us change the values . '''x=75''','''y = 15'''
+
|  Now Let us change the values. '''x=75''', '''y = 15''';
  
 
 
 
|-
 
|-
|  02:38
+
|  02:37
| '''Save''' it '''Run'''
+
| '''Save''' it, '''Run'''.
  
 
|-
 
|-
|  02:43
+
|  02:42
| we   see that the output has   changed  accordingly
+
| we see that the output has changed  accordingly.
  
 
|-
 
|-
 
|  02:48
 
|  02:48
| Now let us try negative values. '''y = -25.''
+
| Now, let us try negative values. '''y = -25''';
 
+
+
  
 
|-
 
|-
 
| 02:57
 
| 02:57
|  '''Save''' '''Run.'''
+
|  '''Save''', '''Run.'''
  
 
|-
 
|-
 
| 03:02
 
| 03:02
|   we   see  that the output of  75  plus  -25 has been printed
+
| we see  that the output of  75  plus  -25 has been printed.
 +
 
 
|-
 
|-
|  03:11
+
|  03:10
|   Now let us try subtraction. '''y = 5'' and change x+y to x-y
+
| Now let us try subtraction. '''y = 5''' and change x+y to x-y.
 
+
 
+
  
 
|-
 
|-
 
|  03:25
 
|  03:25
| '''Save it ''' '''Run.'''
+
| '''Save''' it, '''Run.'''
  
 
|-
 
|-
 
| 03:32
 
| 03:32
|  we   see that the output of 75-5 has been printed,  
+
|  we see that the output of 75-5 has been printed.  
  
 
|-
 
|-
|  03:39
+
|  03:38
| | Now Let us try   multiplication. Change '''minus''' to ''' asterisk'''
+
| Now Let us try multiplication. Change '''minus''' to '''asterisk''' (*).
 
+
+
  
 
|-
 
|-
|  03:47
+
|  03:46
|  '''Save''' '''Run.'''
+
|  '''Save''' and '''Run.'''
  
 
|-
 
|-
 
|  03:52
 
|  03:52
|  we see that  by using   asterisk we could  multiply 75*5. .
+
|  we see that  by using asterisk (*) we could  multiply 75 by 5.
 +
 
 
|-
 
|-
|  03:59
+
|  03:58
|  Now let us try '''division''' Remove   asterisk and type slash
+
|  Now let us try '''division'''. Remove asterisk (*) and type slash.
 
   
 
   
 
|-
 
|-
|  04:08
+
|  04:07
|   '''Save it''' '''Run.'''
+
| '''Save''' it, '''Run.'''
  
 
|-
 
|-
|  04:14
+
|  04:13
 
| As we can see, the output is as expected.
 
| As we can see, the output is as expected.
  
Line 170: Line 153:
 
| 04:18
 
| 04:18
 
| Now let us see what happens when the expected result is a decimal point number.
 
| Now let us see what happens when the expected result is a decimal point number.
 
  
 
|-
 
|-
 
|  04:24
 
|  04:24
 
| Change '''5''' to '''10'''
 
| Change '''5''' to '''10'''
 
  
 
|-
 
|-
 
|  04:28
 
|  04:28
| The result must be 7.5.
+
| The result must be 7.5
  
 
|-
 
|-
 
|  04:30
 
|  04:30
| So let us change the result to a  float.
+
| So, let us change the result to a  '''float'''.
 
+
  
 
|-
 
|-
 
|  04:43
 
|  04:43
| '''Save it''' '''Run'''.  
+
| '''Save''' it, '''Run'''.  
  
 
 
|-
 
|-
|  04:51
+
|  04:50
| Note that although the expected result is 7.5, we get output as 7.0
+
| Note that although the expected result is 7.5, we get output 7.0 .
  
 
|-
 
|-
 
|  04:57
 
|  04:57
| This is because both the operands involved in the division are integers.
+
| This is because both the operands involved in the division are integers.
  
 
|-
 
|-
|  05:02
+
|  05:01
| | Let us change y to a float. y=10f
+
| | Let us change 'y' to a '''float'''. '''y = 10f''';
 
   
 
   
 
|-
 
|-
|05:16
+
|05:15
|   '''Save ''' '''Run'''.  
+
|'''Save''', '''Run'''.  
 
   
 
   
 
 
|-
 
|-
|05:22
+
|05:21
 
|Now we can see that the result is as expected.
 
|Now we can see that the result is as expected.
 
  
 
|-
 
|-
|05:25
+
|05:24
|Keep in mind that when the expected result is a float, one of the operands must be a float to get the expected output.
+
|Keep in mind that when the expected result is a '''float''', one of the operands must be a '''float''' to get the expected output.
  
 
|-
 
|-
| 05:33
+
| 05:32
|  Now let us see what happens when there is more than one operator.Remove all the operands
+
|  Now let us see what happens when there is more than one operator. Remove all the operands.
  
 
|-
 
|-
 
| 05:48  
 
| 05:48  
| int result= 8+4-2. ''Save it ,run''
+
|int result= 8+4-2; '''Save''' it, '''Run'''.
 
   
 
   
 
 
|-
 
|-
 
|06:09
 
|06:09
Line 231: Line 207:
  
 
|-
 
|-
|  06:13
+
|  06:12
| |Now Change '''minus''' to a ''' s lash'''
+
|Now change '''minus''' to a '''slash'''.
 
+
  
 
|-
 
|-
|06:20
+
|06:19
|Now the output would be 6 if the addition is done before division.
+
|Now the output could be 6 if the addition is done before division.
 
+
  
 
|-
 
|-
 
|06:25
 
|06:25
|Or it would be 10 if division is done before addition.
+
|Or it could be 10 if the division is done before addition.
 
+
  
 
|-
 
|-
 
|06:30
 
|06:30
 
|Let us '''Run''' and see the output.
 
|Let us '''Run''' and see the output.
 
  
 
|-
 
|-
 
|06:38
 
|06:38
|As we can see, the output is 10 and  the division is done before addition. This is because the division operator has more precedence than the addition operator.
+
|As we can see, the output is 10 and  the division is done before addition. This is because the division operator has more precedence than the addition '''operator'''.
 
+
  
 
|-
 
|-
Line 261: Line 232:
 
|-
 
|-
 
|  07:04
 
|  07:04
| By adding parentheses, we instruct Java to do the addition before the division.
+
| By adding parentheses, we instruct Java to do the addition before the division.
 
+
  
 
|-
 
|-
 
|  07:10
 
|  07:10
| Let us run the file now.
+
| Let us '''run''' the file now.
 
+
  
 
|-
 
|-
|  07:16
+
|  07:15
| As we can see, addition has been performed first and the output is 6 as expected.
+
| As we can see, addition has been performed first and the output is 6, as expected.
 
+
  
 
|-
 
|-
|  07:23
+
|  07:22
 
| As a rule, keep in mind to use parentheses when the order of operations is not clear.
 
| As a rule, keep in mind to use parentheses when the order of operations is not clear.
  
 
|-
 
|-
|  07:37
+
|  07:36
|   This brings us  to the end of this tutorial.  
+
| This brings us  to the end of this tutorial.  
  
 
|-
 
|-
 
|  07:40
 
|  07:40
| we have learnt  
+
| We have learnt:
  
 
|-
 
|-
 
| 07:41   
 
| 07:41   
| '''How to''' '''perform basic mathematical operations in Java.'''
+
|How to perform basic mathematical operations in Java.
  
 
|-
 
|-
 
|  07:44
 
|  07:44
| ''' operator precedence, and, '''
+
| '''operator precedence''' and
  
 
|-
 
|-
| 07:46 
+
| 07:45
| '''How to override it.'''
+
| How to '''override''' it.
  
 
|-
 
|-
 
|  07:49
 
|  07:49
| As an assignment for this tutorial Find out what is meant by the '''modulo''' operator and what it does.
+
| As an assignment for this tutorial: find out what is meant by the '''modulo''' operator and what it does.
 
+
+
+
  
 
|-
 
|-
|  07:58
+
|  07:57
| To know more about the '''Spoken Tutorial''' project, watch the video available at the following link,
+
| To know more about the Spoken Tutorial project, watch the video available at the following link.
 
|-
 
|-
|  08:03
+
|  08:02
|   It summarizes the project.  
+
| It summarizes the project.  
 
|-
 
|-
|  08:06
+
|  08:05
| If you do not have good bandwidth you can download and watch it
+
| If you do not have good bandwidth, you can download and watch it.
 
|-
 
|-
|  08:11
+
|  08:10
|   The Spoken Tutorial Team.
+
| The Spoken Tutorial Team:
 
|-
 
|-
 
|  08:12
 
|  08:12
| Conducts workshops using '''spoken tutorials'''
+
| Conducts workshops using spoken tutorials.
 
|-
 
|-
|08:15 
+
|08:14
 
|  Gives certificates to those who pass an online test.  
 
|  Gives certificates to those who pass an online test.  
 
|-
 
|-
Line 328: Line 293:
  
 
|-
 
|-
| 08:25 
+
| 08:24
| The '''Spoken Tutorial Project''' is a part of the '''Talk to a Teacher''' project .
+
| The Spoken Tutorial project is a part of the Talk to a Teacher project.
 
|-
 
|-
 
|  08:29
 
|  08:29
| It is supported by the '''National Mission on Education through ICT, MHRD, Government of India. |-
+
| It is supported by the National Mission on Education through ICT, MHRD, Government of India.  
 +
|-
 
|  08:35
 
|  08:35
| '''More information on this Mission is available at the following link '''spoken HYPHEN tutorial DOT org SLASH NMEICT HYPHEN Intro'''
+
| More information on this mission is available at the following link '''spoken HYPHEN tutorial DOT org SLASH NMEICT HYPHEN Intro'''.
  
 
|-
 
|-
 
|  08:39
 
|  08:39
 
|  This tutorial has been contributed by '''TalentSprint'''. Thanks for joining.
 
|  This tutorial has been contributed by '''TalentSprint'''. Thanks for joining.
 
 
 
  
 
|}
 
|}

Latest revision as of 19:20, 20 February 2017

Time Narration
00:01 Welcome to the tutorial on Arithmetic Operations in Java.
00:05 In this tutorial, you will learn about the various Arithmetic Operators namely

Addition

Subtraction

Multiplication

Division and

How to use them.

00:16 For this tutorial, we are using:

Ubuntu 11.10,

JDK 1.6 and

Eclipse 3.7

00:24 To follow this tutorial, you must have eclipse installed on your system
00:28 and you must know how to create, save and run a file in Eclipse.
00:32 If not, for relevant tutorials, please visit our website as shown.
00:42 Here is a list of operators and the mathematical operations they perform

plus (+) symbol for addition minus (-) for subtraction asterisk (*) for multiplication and slash (/) for division

00:54 We shall look at each of them in detail.
01:05 Here we have the 'Eclipse IDE' and the skeleton required for the rest of the code.
01:10 We have created a class by name ArithmeticOperations and added the main method.
01:17 Let us add some variables.
01:22 int x = 5;
01:26 int y = 10;

int result;

01:35 'x' and 'y' will be operands and the result will store the output of the operations.
01:41 Let us add them and print the result. result= x+y; system. out. println in parentheses result.
02:10 Save it with Control S and control F11 to Run.
02:17 We see that the output of the addition has been stored in result and the value has been printed.
02:24 Now Let us change the values. x=75, y = 15;
02:37 Save it, Run.
02:42 we see that the output has changed accordingly.
02:48 Now, let us try negative values. y = -25;
02:57 Save, Run.
03:02 we see that the output of 75 plus -25 has been printed.
03:10 Now let us try subtraction. y = 5 and change x+y to x-y.
03:25 Save it, Run.
03:32 we see that the output of 75-5 has been printed.
03:38 Now Let us try multiplication. Change minus to asterisk (*).
03:46 Save and Run.
03:52 we see that by using asterisk (*) we could multiply 75 by 5.
03:58 Now let us try division. Remove asterisk (*) and type slash.
04:07 Save it, Run.
04:13 As we can see, the output is as expected.
04:18 Now let us see what happens when the expected result is a decimal point number.
04:24 Change 5 to 10
04:28 The result must be 7.5
04:30 So, let us change the result to a float.
04:43 Save it, Run.
04:50 Note that although the expected result is 7.5, we get output 7.0 .
04:57 This is because both the operands involved in the division are integers.
05:01 Let us change 'y' to a float. y = 10f;
05:15 Save, Run.
05:21 Now we can see that the result is as expected.
05:24 Keep in mind that when the expected result is a float, one of the operands must be a float to get the expected output.
05:32 Now let us see what happens when there is more than one operator. Remove all the operands.
05:48 int result= 8+4-2; Save it, Run.
06:09 As we can see, the output is as expected.
06:12 Now change minus to a slash.
06:19 Now the output could be 6 if the addition is done before division.
06:25 Or it could be 10 if the division is done before addition.
06:30 Let us Run and see the output.
06:38 As we can see, the output is 10 and the division is done before addition. This is because the division operator has more precedence than the addition operator.
06:50 In such situations, if we need to override the precedence, we use parentheses.
07:04 By adding parentheses, we instruct Java to do the addition before the division.
07:10 Let us run the file now.
07:15 As we can see, addition has been performed first and the output is 6, as expected.
07:22 As a rule, keep in mind to use parentheses when the order of operations is not clear.
07:36 This brings us to the end of this tutorial.
07:40 We have learnt:
07:41 How to perform basic mathematical operations in Java.
07:44 operator precedence and
07:45 How to override it.
07:49 As an assignment for this tutorial: find out what is meant by the modulo operator and what it does.
07:57 To know more about the Spoken Tutorial project, watch the video available at the following link.
08:02 It summarizes the project.
08:05 If you do not have good bandwidth, you can download and watch it.
08:10 The Spoken Tutorial Team:
08:12 Conducts workshops using spoken tutorials.
08:14 Gives certificates to those who pass an online test.
08:18 For more details, please write to spoken HYPHEN tutorial DOT org.
08:24 The Spoken Tutorial project is a part of the Talk to a Teacher project.
08:29 It is supported by the National Mission on Education through ICT, MHRD, Government of India.
08:35 More information on this mission is available at the following link spoken HYPHEN tutorial DOT org SLASH NMEICT HYPHEN Intro.
08:39 This tutorial has been contributed by TalentSprint. Thanks for joining.

Contributors and Content Editors

Arya Ratish, Gaurav, Krupali, PoojaMoolya, Priyacst, Sandhya.np14, Sneha