-
Notifications
You must be signed in to change notification settings - Fork 52
Expand file tree
/
Copy pathMethods.java
More file actions
57 lines (51 loc) · 1.39 KB
/
Methods.java
File metadata and controls
57 lines (51 loc) · 1.39 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
53
54
55
56
57
public class Methods
{
public static void main(String[] args)
{
printAverage(20, 30);
double average = getAverage(20,40);
System.out.println("Average: " + average);
String fullName = fullName("Anushka", "Raj");
System.out.println(fullName);
int value = 20;
if(isValid(value))
{
System.out.println("The value is in range!");
}
else
{
System.out.println("The value is not in range");
}
}
/****
* This method prints the average of two numbers
* @param val1 The first value
* @param val2 The second value
*/
public static void printAverage(int val1, int val2)
{
double average = (val1 + val2) / 2.0;
System.out.println("Average: " + average);
}
/****
* This method calculates the average and return it
* @param val1 The first value
* @param val2 The second value
* @return The average of two values
*/
public static double getAverage(int val1, int val2)
{
double average = (val1 + val2) / 2.0;
return average;
}
public static String fullName(String name, String surname)
{
return name + " " + surname;
}
//range between 1 and 100
public static boolean isValid(int number)
{
boolean status;
return (number >= 1 && number <=100);
}
}