-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathDay6.java
More file actions
106 lines (88 loc) · 2.66 KB
/
Day6.java
File metadata and controls
106 lines (88 loc) · 2.66 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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
// ---------------------------------------------------
// Author : Benjamin Kataliko Viranga
// Community : Stunt Business
// Community website : www.stuntbusiness.com
//
// 30 Days - Q&A Java basic
// Day 6 : Conditions and booleans
// Day 6 | IG : https://www.instagram.com/benjivrik/
// ----------------------------------------------------
// what would be the output of this program ?
import java.util.Scanner;
public class Day6 {
/**
*
* if( condition )
{
when this condition is True, this block executes
}
else if( condition )
{
when the previous condition is not executed
if this condition is True, this block executes
}
else
{
if none of the above conditions are satisfied, this
block executes
}
*/
/**
* return the double of the parameter
* @param value
* @return
*/
public static int double_parameter(int value)
{
return value * 2;
}
/**
* return the value of the parameter divide by two
* @param value
* @return
*/
public static double divide_parameter_by_two(double value)
{
return value / 2;
}
/**
* return add 2 to the value of the parameter
* @param value
* @return
*/
public static int add_two_to_the_parameter(int value)
{
return value + 2;
}
public static void main(String[] args)
{
Scanner sc= new Scanner(System.in);
String stop = "n";
while(stop.equals("n"))
{
int user_value;
// Request the user to enter a value;
System.out.printf("\nPlease enter an integer : ");
user_value = sc.nextInt();
if( user_value < 5)
{
//add two to the parameter
System.out.printf("\nAdding 2 to your value %d gives %d.\n",user_value, Day6.add_two_to_the_parameter(user_value));
}
else if (user_value >= 5 && user_value < 10)
{
//divide
System.out.printf("\nDividing your value %d by 2 gives %.2f.\n",user_value, Day6.divide_parameter_by_two(user_value));
}
else // user
{
// multiply
System.out.printf("\nMultiplying your value %d by 2 gives %d.\n",user_value, Day6.double_parameter(user_value));
}
System.out.printf("\nDo you want to stop ?(y/n) : ");
stop = sc.next();
}
sc.close();
System.out.println("End of program.");
}
}