-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEx9Method.java
More file actions
52 lines (44 loc) · 1.44 KB
/
Ex9Method.java
File metadata and controls
52 lines (44 loc) · 1.44 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
package JavaEntry;
public class Ex9Method {
static void firstMethod(){
System.out.println("This is my first Java Method");
}
// One functiion, multiple output
static void printMyName(String name, int roll){
System.out.println("Name: " + name + ", Roll no: " + roll);
}
static void checkAgeGroup(int age){
if(age >= 18){
System.out.println("Adult, your age is: " + age);
}else {
System.out.println("Not Adult, you age is: " + age);
}
}
static int multiplyTwoNum(int x, int y){
return x * y;
}
//Method override (If required)
static double multiplyTwoNum(double x, double y){
return x * y;
}
// Recursive function: making a function call itself till its reach the result.
static int recurFunc(int num){
if(num > 0){
return num + recurFunc(num - 1); // Result will be (5+4+3+2+1 = 15);
}else {
return 0;
}
}
public static void main(String[] args){
firstMethod();
printMyName("Banti", 001);
printMyName("Anand", 002);
printMyName("Amol", 003);
checkAgeGroup(29);
int sum = multiplyTwoNum(5, 10);
System.out.println("5 X 10 = " + sum);
System.out.println("5 X 10 = " + multiplyTwoNum(5.55, 10.15));
int reCursRes = recurFunc(5);
System.out.println("ReCurssive Function: " + reCursRes);
}
}