-
-
Notifications
You must be signed in to change notification settings - Fork 37
Expand file tree
/
Copy pathMencari Nilai FPB
More file actions
46 lines (39 loc) · 1.27 KB
/
Mencari Nilai FPB
File metadata and controls
46 lines (39 loc) · 1.27 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
package mencari_fpb;
import java.util.Scanner;
/**
*
* @author Afwaans
*/
public class Mencari_fpb {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int m, n, r, q;
String next = "y";
do{
System.out.println("-----Selamat Datang Di Program Mencari FPB-----");
System.out.print("Masukkan Nilai m: ");
m = sc.nextInt();
System.out.print("Masukkan Nilai n: ");
n = sc.nextInt();
System.out.println("----------------------");
if(n==0){
System.out.println("FPB dari (" +m+","+n+ ") adalah "+ m);
}else {
System.out.println("m = " +m +" n = "+n);
do{
r = m/n;
q = m-(r*n);
m = n;
n = q;
System.out.println("m = " +m +" n = "+n + " r = "+ q);
}while(n > 1);
System.out.println("----------------------");
System.out.println("Maka FPB = " + m);
}
Scanner lagi= new Scanner(System.in);
System.out.println("FPB Lain? ");
System.out.println("y/t");
next = lagi.nextLine();
}while(next.equalsIgnoreCase("y"));
}
}