Skip to player
Skip to main content
Search
Connect
Watch fullscreen
Like
Bookmark
Share
More
Add to Playlist
Report
(Sigma batch 2025) syntax with parameters by shradha didi
Prateek Prajapati
Follow
4 months ago
Sigma batch
Category
📚
Learning
Transcript
Display full video transcript
00:00
Now let's discuss another syntax of the functions in which there are parameters
00:06
Parameters are our function's input
00:09
How did we decide the output? We decided the output from a return type
00:14
In this function, there is a thing called parameters that tells us what should be input
00:20
In this syntax, first we write the return type function
00:23
Then we write the name function
00:25
And we write all the parameters that we want to take into the function as input
00:30
So here, this parenthesis and this parenthesis are our function's input
00:37
Then we write our function's body
00:39
In which we write all our code and logic
00:42
And in the last, we have a return statement
00:44
Return statement can be changed depending on how our function's return type
00:48
Let's discuss a sample program
00:51
What do we want to do? We want to make a function
00:54
In the function, we are going to give input a and a number b
00:58
And we are going to output sum of a, b
01:02
How do we write this code?
01:04
First we write our code in the main function
01:06
What do we want to do? We will make a scanner class
01:09
System.in
01:12
We will import our package
01:15
Java.util.all
01:19
Now what do we want to do?
01:20
First we will input our first number
01:23
Then we will use second number
01:25
Then we are going to calculate
01:27
The sum of a variable
01:29
Int sum is equal to a plus b
01:31
And what do we do?
01:33
Finally we will print this sum
01:35
Sum is sum
01:37
Now what is the whole work
01:39
We have to shift this work
01:41
We have to shift this function
01:43
So let's write a function
01:45
Also, how many functions in a class
01:47
We can make a function of a print hello world
01:49
We will make a function of a sum
01:51
Now we can make a function of multiple functions
01:53
In a single class
01:55
First we will write public static
01:57
First we will write public static
01:59
Now when we start this function
02:01
We will keep the return type
02:02
We will keep the return type
02:03
That we are not doing anything
02:04
And we will give it the name
02:05
Calculate sum
02:08
In the sum
02:09
In the sum
02:10
We will not send anything to input
02:11
What do we do?
02:12
We will take the whole code
02:14
And take it here
02:16
And what will we do?
02:18
Main function simply call
02:20
And what will we do?
02:22
Main function simply call
02:24
Calculate sum
02:25
Calculate sum
02:27
Now let's run this code
02:29
The main function has called
02:31
Calculate sum
02:32
We are here
02:33
In this Calculate sum
02:35
It has made a scanner class
02:37
So first we need a first number
02:39
A
02:40
We will pass 5
02:41
Then we need a second number
02:42
B
02:43
We will pass 10
02:44
And then we will have
02:46
Calculate sum
02:47
Which is going to be 15
02:49
Now we will change some changes
02:51
What changes are
02:53
This scanner
02:54
And this input
02:55
We will shift the same
02:56
In the main function
02:58
In the main function
02:59
The main function will scan
03:00
The main function will see
03:01
A and B
03:02
But this A and B
03:04
How will reach this sum function?
03:05
They will reach the parameters
03:07
Where do we write the parameters?
03:09
We will write the parameters
03:10
In the parentheses
03:11
In the parentheses
03:12
First we will write our first parameter
03:14
Its type
03:15
Int
03:16
And name A
03:17
Then our second parameter
03:18
Int B
03:19
Int
03:20
Int
03:21
So
03:22
So our first parameter is int a, second parameter is int b
03:27
These two are in our calculate sum function
03:30
If I remove them, the parameters from here
03:34
What will happen? There will be an error
03:36
Why will it happen? Because this function doesn't know what a and b
03:40
Then I will know when I pass these two a and b
03:43
I will pass these parameters to this function
03:45
If I name number 1 or number 2
03:51
So my sum will calculate for number 1 and number 2
03:57
So I have written a definition of a function
03:59
Which calculates the sum
04:01
These two numbers will take number 1 and number 2
04:02
They will calculate the sum and print it in the print
04:05
What do I have to do in the main function?
04:08
I have taken a and b
04:10
Now I have to call the calculate sum
04:12
But with the calculate sum, I have to pass my two integer values
04:17
Because the calculate sum requires two numbers
04:20
So what will I do? I will pass a first and then b
04:23
Let's save and run again
04:25
So first number is 5, second number is 10 and sum is 15
04:31
So what did I do? I have passed my numbers in this function
04:36
How did I pass it?
04:37
I have to pass it in parenthesis
04:39
First number is 1st number and then second number
04:41
And in my function
04:43
I received those numbers as parameters
04:45
And then I have removed the sum and print it in the sum
04:49
Now this is the work of the sum to print it
04:51
I can do this in the main function
04:53
How can I do this?
04:55
So what do I do here?
04:57
I will write int sum is equal to calculate sum
05:02
And this function I will return type and write int
05:05
And here I will return sum
05:09
So what did I do?
05:10
I have made a function that calculates sum
05:13
And now I have made a function of number 1 and number 2
05:15
Which also comes in the input
05:16
And the sum is calculated and returned
05:19
So I have returned sum
05:21
Who did I return?
05:22
Who did I call it?
05:23
Who did I call it?
05:24
The main function has called it
05:25
That's why the calculate sum
05:27
The return type of sum is int
05:29
Because it is a integer value sum
05:31
How did it return?
05:33
How did it return?
05:34
It returned from this statement
05:36
And from this assignment operator
05:38
Now I can store it somewhere
05:40
So I have sum name the other variable
05:43
This sum variable
05:45
And this sum variable
05:46
Both are different
05:47
Because these are different functions
05:49
We will study scopes
05:51
In this chapter
05:53
We will understand the details
05:55
How these variables are different
05:57
They are different
05:58
Same variable
05:59
So I have stored this variable
06:01
And then I have done that sum
06:03
Let's save it
06:05
And run
06:07
So first number 5
06:08
Second number 10
06:10
So I have printed sum is 15
06:12
And how did I do this?
06:13
I have simply done these 3 lines
06:15
Where there is a function
06:16
Which takes some input
06:18
Some work
06:19
And then
06:20
It returns some output
06:22
And then
06:23
And then
06:24
Also
06:26
So
Be the first to comment
Add your comment
Recommended
1:22
|
Up next
Sigma & Take That On GMB #Cry
Michelle Thornton
10 years ago
0:11
Sigma rule
Jack Sparrow
2 years ago
0:21
Sigma rule _#320 #sigmarule #trending
RANDOM CLIPS
3 years ago
3:42
(Sigma batch 2025) product os a&b by shradha didi
Prateek Prajapati
4 months ago
8:15
(Sigma batch 2025) call by values by shradha didi
Prateek Prajapati
4 months ago
5:10
(Sigma batch 2025) what happened in memory by shradha didi
Prateek Prajapati
4 months ago
1:55
(Sigma batch 2025) parameters v/s arguments by shradha didi
Prateek Prajapati
4 months ago
10:23
(Sigma batch 2025) syntax function code by shradha didi
Prateek Prajapati
4 months ago
2:30
(Sigma batch)Introduction to a Function by shradha didi
Prateek Prajapati
4 months ago
0:51
Former Aide Claims She Was Asked to Make a ‘Hit List’ For Trump
Veuer
2 years ago
1:08
Musk’s X Is ‘the Platform With the Largest Ratio of Misinformation or Disinformation’ Amongst All Social Media Platforms
Veuer
2 years ago
4:50
59 companies that are changing the world: From Tesla to Chobani
Fortune
2 years ago
0:46
3 Things to Know About Coco Gauff's Parents
People
2 years ago
1:18
USC vs. Colorado: Can Caleb Williams Earn a New Heisman Moment?
SportsGrid
2 years ago
1:04
Vic Mensa Reveals Celebrity Crush, Biggest Dating Pet Peeve & More on Speed Dating | Billboard News
Billboard
2 years ago
1:09
Hollywood Writers Reach ‘Tentative Agreement’ With Studios After 146 Day Strike
Veuer
2 years ago
1:26
Love is Blind stars admit they're burnt out from social media
Fortune
2 years ago
2:01
NHA Customers in Limbo as Company Faces Potential Merger
SportsGrid
2 years ago
2:55
Vanilla Ice Explains How the 90’s Shaped America
FACTZ
2 years ago
0:36
Amazon’ Prime Video Will Show Commercials Starting Next Year
Veuer
2 years ago
11:13
Pokimane Answers The Web's Most Searched Questions
WIRED
2 years ago
4:16
BREAKING NEWS: Matt Gaetz Tells House Committee: 'I'm Not Going To Vote For A Continuing Resolution'
Forbes Breaking News
2 years ago
1:00
What's Popular on Uber Eats?
Stringr
2 years ago
2:50
MÃ¥neskin Performs "HONEY" at MSG
Rolling Stone
2 years ago
12:13
Matt Rife Hilariously Roasts Your Dating Profiles | Cosmopolitan
Cosmopolitan USA
2 years ago
Be the first to comment