- You can start the dialog one by one. If we define dialogue as an argument, the topic of discussion in Article ref. Therefore, any changes in this dialog interrupted the discussion.
-
Since you can change the old key path on the path, you can change the dialog on the path. Hold the title of the discussion without square footage during the conversation to put the discussion on the page. Unlike C / C ++, in Java every dialog knows how long it takes to use its parameters, so we do not want to write one part as an argument as another argument. For example, we have a ten-line number.
Example
- import java.util.Scanner;
- public class ArraysToMethod {
public int max(int [] array) {
int max = 0; - for(int i=0; i<array.length; i++ ) {
if(array[i]>max) {
max = array[i];
}
}
return max;
} - public int min(int [] array) {
int min = array[0];for(int i = 0; i<array.length; i++ ) {
if(array[i]<min) {
min = array[i];
}
}
return min;
} - public static void main(String args[]) {
Scanner sc = new Scanner(System.in);
System.out.println(“Enter the size of the array that is to be created::”);
int size = sc.nextInt();
int[] myArray = new int[size];
System.out.println(“Enter the elements of the array ::”); - for(int i=0; i<size; i++) {
myArray[i] = sc.nextInt();
}
ArraysToMethod m = new ArraysToMethod();
System.out.println(“Maximum value in the array is::”+m.max(myArray));
System.out.println(“Minimum value in the array is::”+m.min(myArray));
}
}
Output:
Enter the size of the array that is to be created ::
6
Enter the elements of the array ::
12
7
43
64
87
Maximum value in the array is ::87
Minimum value in the array is ::7
In this example: we share the numbers with the concept of converting matrices to methods. Informal conversations are converted to method (). In a more accurate translation, the instructions for the use of numerical methods and inversions were given.
Passing Arguments to Methods in Java
There are two ways of passing arguments to methods in Java:
-
- Pass by value
- Pass by reference
1. Pass by value
If the dispute is outside the scope of the pricing method, only a short copy of the change will be sent to the receiving method. Internal boundary changes are not caused by the phone. This is to ensure that the change on the phone remains unchanged after a return.
Example:
import
<a href=
"
data-internallinksmanager029f6b8e52c=
"16"
>java</a>.io.*;
public
class
Sum {
static
int
CaiculateTotal(
int
n1) {
int
total=
0
;
int
marks[] =
new
int
[6
]:
try
{
BufferedReader br= newBufferedReader(
new
InputStreamReader(System.in));
for
(
int
i=
0
; i<n
1
; i++) {
marks[i]= Integer.parselnt(br.readLine());
total+=marks[i];
}
}
catch
(Exception e) {
System.out.println(
"Array out of range"
);
}
return
total;
}
public
static
void
main(String args[])
throws
IOException {
int
n,Max;
System.out.println(
"Enter the numbers :"
);
Max = CalculateTotal(6
);
System.out.println(
"Sum of the numbers is:"
+Max);
}
}
output:
Enter the numbers
The program converts the value 6 to a common value. Calculating Total n1 is a great way to stop 6 at a time.
2. Pass by reference
In turn, before it is on its way, the return rotation returns to the correct path. This feature does not use Java to separate call paths. Instead of planning, strategies are planned based on usage, and therefore each change is selected. The program offers Java phones over one application.
Example
Program to illustrate pass by reference.
import
java.io.*;
class
swap_ref {
static
void
swap(First ob) {
int
temp;
temp=ob.a;
ob.a=ob.b;
ob.b=temp;
}
public
static
void
main(String args[ ]) {
First ob=
new
First(
10
,
20
);
System.out.println(
"Before SWAP"
);
System.out.println(
"a="
+ob.a+
"b="
+ob.b);
swap(ob);
System.out.println(
"After SWAP"
);
System.out.println (
"a="
+ob.a +
"b="
+ob.b);
}
}
class
First {
int
a;
int
b;
First(
int
x,
int
y) {
a = x;
b = y;
}
}
output:
Before SWAP
b = 10
Here differences of opinion are called two kinds, and every deception thus affects the old. Therefore, the change in value after the changed estimate is called the zero value.