Skip to playerSkip to main content
  • 4 months ago
Sigma batch by apna college
Transcript
00:00Next question we will do is find product of A and B
00:03We will give two numbers A and B
00:06And we will find out their product
00:08We will multiply A by B by the result
00:11We will find out this
00:13Return
00:14So for this we will make a function
00:16What will return type of function?
00:19Return type int
00:20Because we will make product and return it from the function
00:24What can we keep this function?
00:26We can keep the name of this function
00:28And what will happen in this function?
00:30There will be two parameters
00:32The first parameter will be integer A
00:36And the second parameter will be integer B
00:39And my job is to multiply both in this function
00:43So what will I do?
00:45I will make a third variable
00:47Which I will store A multiplied by B
00:50And here I will return my product variable
00:55I will always add public static
00:57Because this is my access modifier
00:59So I will return my product here
01:01What will I do in the main function?
01:03I will add call in the main function
01:05I will multiply
01:06I will pass in the multiply
01:07I will pass A
01:08I will pass A
01:09Or I can pass 3 or B
01:11I can pass 5
01:12So we can pass directly values in our java functions
01:16And then whatever output comes
01:18I can store that output
01:20In this new variable
01:23Prod
01:24Which I will do in the next
01:26Print
01:27So in this way my flow will be
01:29I have to make this function
01:30Which will be written
01:31In the main function
01:33I will call in the main function
01:35I will pass 2 values
01:36A and B
01:37And the answer is returned
01:39I will store it in this variable
01:41I will then print
01:43Print
01:44So let's write this function
01:46In the function
01:47First we will write public
01:49Static
01:50Int
01:51Because it will be return type
01:53Int
01:54The name we have to give
01:55Multiply
01:56In the multiply
01:57First we will have a parameter
01:59Integer A
02:00Then Integer B
02:01After that
02:02What will I do?
02:03I will make a variable
02:05Product
02:06In which I will store
02:07A multiplied by B
02:08And I will return
02:10Product
02:11Product
02:12What will I do in the main function
02:15In the main function
02:16I will make two variables
02:17Int A
02:18Which I will store
02:193
02:20Int B
02:21Which I will store
02:225
02:23Now I am going to call
02:24Multiply
02:25In the multiply
02:26I have passed the same A and B
02:27But since the call by value
02:28So A and B
02:29Is always copy and pass
02:30Multiply
02:31As I will return this function
02:32I will give the product
02:34I will store it here
02:36How will I store it?
02:38I will store it
02:39A variable
02:40In the prod
02:41Now I will do the value
02:42I will print
02:43A multiplied by B
02:45Is equal to
02:46Save
02:47And
02:48A multiplied by B
02:49Is equal to
02:50Save
02:51And
02:52So A multiplied by B
02:53Is equal to 15
02:54Because 3 multiplied by 5
02:56Is equal to 15
02:57Because 3 multiplied by 5
02:58Is equal to 15
02:59So
03:04In the whole code
03:05When I have to multiply two numbers
03:06I will simply
03:07Where
03:08I will multiply two numbers
03:09Here
03:10I will multiply 10
03:11And
03:1220
03:13So
03:14I will simply
03:16Call
03:17In the prod
03:18Now I will store a new value
03:20And
03:21What will I do?
03:23I will print it
03:24So
03:25Now I will have two multiplications
03:27And
03:28A into B
03:29First of all
03:3015
03:31Then
03:3210
03:33And
03:3420
03:35Which is
03:36200
03:37So
03:38When I will work
03:39Two numbers
03:40I will write a straight line
03:41Which I can call the multiply function
03:42Video
03:45And
03:46In
03:47The
03:48Of
03:49No
03:50No
03:51But
03:53You
03:54The
03:55likely
03:56That
03:57Was
03:58That
03:59Were
04:00Us
04:01You
04:02I
04:03I
04:04Not
04:05States
04:06Any
04:07You
04:08Any
Be the first to comment
Add your comment

Recommended