Skip to content

Commit 2553064

Browse files
committed
added classes_And_Objects\Method_Return_Types.java
1 parent 30ce5b3 commit 2553064

File tree

1 file changed

+48
-0
lines changed

1 file changed

+48
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
package classes_And_Objects;
2+
3+
public class Method_Return_Types {
4+
public static void main(String[] args) {
5+
sayHelloWorld();
6+
sayHelloTo("Bob");
7+
sayHelloTo("John");
8+
sayHelloTo("Mateo");
9+
10+
int x = returnFive();
11+
System.out.println(x);
12+
13+
//f(x) = x * x
14+
int result = square(5);
15+
System.out.println(result);
16+
}
17+
18+
static int square(int x) {
19+
return x * x;
20+
}
21+
22+
23+
// this method returns an int type with the value 5
24+
static int returnFive() {
25+
return 5;
26+
}
27+
28+
// this method simply says "Hello World"
29+
static void sayHelloWorld() {
30+
System.out.println("Hello, World!");
31+
}
32+
33+
// this method will say hello to whatever name is passed when called
34+
static void sayHelloTo(String name) {
35+
System.out.println("Hello, " + name);
36+
}
37+
38+
}
39+
40+
41+
42+
43+
44+
45+
46+
47+
48+

0 commit comments

Comments
 (0)