-
Notifications
You must be signed in to change notification settings - Fork 0
/
methodj.java
52 lines (33 loc) · 1.17 KB
/
methodj.java
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
public class methodj {
// define function return void means no return value
static void myMethod(String fname) {
System.out.println("I just got executed!"+fname);
}
// define function return int value define as int
static int Method(int x) {
return 5 + x;
}
static int myMethods(int x, int y) {
return x + y;
}
// check the age function
static void checkAge(int age) {
// If age is less than 18, print "access denied"
if (age < 18) {
System.out.println("Access denied - You are not old enough!");
// If age is greater than, or equal to, 18, print "access granted"
} else {
System.out.println("Access granted - You are old enough!");
}
}
// below code call the function
public static void main(String[] args) {
myMethod("rahul");
myMethod("Shiv Sisye");
myMethod("shiv ki daya hai");
System.out.println(Method(3));
int z = myMethods(55, 3);
System.out.println(z);
checkAge(20); // call the checkAge function
}
}