-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMultiplierProgram.java
More file actions
53 lines (41 loc) · 1.52 KB
/
MultiplierProgram.java
File metadata and controls
53 lines (41 loc) · 1.52 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
package com.lftechnology.programs;
import java.util.Scanner;
public class MultiplierProgram {
private int numberOfMultiple;
private int firstMultiplier;
private int secondMultiplier;
private Scanner scanner;
public MultiplierProgram() {
}
public void run() {
this.initiateRun();
System.out.println("->Please Enter the Number of Multiplier");
scanner = new Scanner(System.in);
this.numberOfMultiple = scanner.nextInt();
System.out.println("->Please Enter First Multiplier");
this.firstMultiplier = scanner.nextInt();
System.out.println("->Please Enter Second Multiplier");
this.secondMultiplier = scanner.nextInt();
int sum = calculateMultiplier();
System.out.println("Sum of multiple by " + this.firstMultiplier + " and " + this.secondMultiplier + " below "
+ this.numberOfMultiple + "=" + sum);
this.endRun();
}
public int calculateMultiplier() {
int sum = 0;
for (int i = 0; i < this.numberOfMultiple; i++) {
if ((i % this.firstMultiplier) == 0 || (i % this.secondMultiplier) == 0) {
sum += i;
}
}
return sum;
}
public void initiateRun() {
System.out.println("\n");
System.out.println("->Executing Multiplier");
}
public void endRun() {
System.out.println("-----------------------------------------");
System.out.println("-----------------------------------------\n\n");
}
}