0% found this document useful (0 votes)
18 views1 page

FPB

The document describes a Java program that calculates the greatest common divisor (FPB) of two integers entered by the user. The program uses a while loop to repeatedly divide the larger number by the smaller number until the remainder is zero.

Uploaded by

ROSALIAART
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
18 views1 page

FPB

The document describes a Java program that calculates the greatest common divisor (FPB) of two integers entered by the user. The program uses a while loop to repeatedly divide the larger number by the smaller number until the remainder is zero.

Uploaded by

ROSALIAART
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 1

/*

* To change this template, choose Tools | Templates


* and open the template in the editor.
*/
package tugasdua;
import java.io.*;
public class FPB {
public static void main (String [] args){
DataInputStream angka= new DataInputStream(System.in);
int a=0 , b =0 , ulang=1;
int sisa;
while(ulang==1){
System.out.println("masukkan nilai a :");
try {
a=Integer.parseInt(angka.readLine());}
catch (IOException e) {System.out.println("error");}
System.out.println("masukkan nilai b :");
try{
b=Integer.parseInt(angka.readLine());}
catch( IOException e){System.out.println("error");}
sisa=a%b;
while (sisa!=0){
a=b;
b=sisa;
sisa=a%b; }
System.out.println("FPBnya adalah "+b);
System.out.println("cobalagi ?"
+"\n 1. yes"
+"\n 2.no");

try{
ulang=Integer.parseInt(angka.readLine());}
catch(IOException e){System.out.println("error");}
}
}
}

You might also like