-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLab6.java
More file actions
39 lines (34 loc) · 872 Bytes
/
Lab6.java
File metadata and controls
39 lines (34 loc) · 872 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
29
30
31
32
33
34
35
36
37
38
39
package lab6;
import java.util.Scanner;
public class Lab6 {
private int value1, value2, gcf;
private Scanner input = new Scanner (System.in);
public void getValues() {
System.out.print("Enter value1: ");
value1 = input.nextInt();
while(value1 <= 0) {
System.out.print("Enter value1 that is greater than 0: ");
value1 = input.nextInt();
}
System.out.print("Enter value2: ");
value2 = input.nextInt();
while(value2 <= 0) {
System.out.print("Enter value2 that is greater than 0: ");
value2 = input.nextInt();
}
}
public void calculateGcf() {
int a = value1;
int b = value2;
int temp;
while (b != 0) {
temp = a % b;
a = b;
b = temp;
}
gcf = a;
}
public void display() {
System.out.println("The greatest common factor of " + value1 + " and " + value2 + " is " + gcf);
}
}