-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSquare.java
More file actions
28 lines (23 loc) · 954 Bytes
/
Square.java
File metadata and controls
28 lines (23 loc) · 954 Bytes
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
// Write a Java program to find a Square of given number belonging to the three data types, namely Integers, Floating Point & Double Precision number using Overloading of Fucntions
public class Square {
public static void main(String[] args) {
int num1 = 5;
float num2 = 3.14f;
double num3 = 7.5;
System.out.println("Square of " + num1 + " is " + square(num1));
System.out.println("Square of " + num2 + " is " + square(num2));
System.out.println("Square of " + num3 + " is " + square(num3));
}
// Function overloading for finding square of integer
public static int square(int num) {
return num * num;
}
// Function overloading for finding square of float
public static float square(float num) {
return num * num;
}
// Function overloading for finding square of double
public static double square(double num) {
return num * num;
}
}