Package javaapplication24;
Class Negativeintegerexception extends exception{
String message;
Public Negativeintegerexception () {
Message= "Method parameter value is not a positive integer";}
Public String toString () {
return message;}
}
Class maxcommondivisor{
public int getmaxcommondivisor (int a,int b) throws negativeintegerexception{
if (a<0| | B<0)
throw new Negativeintegerexception ();
int r=0;
if (b>a) {
int t=a;a=b;b=t;}
R=a%b;
while (r!=0) {
A=b;
B=r;
R=a%b;}
return b;}}
Class Mincommonmultiple extends maxcommondivisor{
public int getmincommonmultiple (int a,int b) throws negativeintegerexception{
if (a<0| | B<0)
throw new Negativeintegerexception ();
int y=0;
int X=getmaxcommondivisor (A, b);
y= (A*B)/x;
return y;
}}
/**
*
* @author Qingzhu
*/
public class JavaApplication24 {
/**
* @param args the command line arguments
*/
public static void Main (string[] args) {
int Maxcommondivisor, mincommonmultiple;
Maxcommondivisor max=new maxcommondivisor ();
Mincommonmultiple min=new mincommonmultiple ();
Try{maxcommondivisor=max.getmaxcommondivisor (18, 12);
System.out.println ("Greatest common divisor:" +maxcommondivisor);
Mincommonmultiple=min.getmincommonmultiple (18, 12);
SYSTEM.OUT.PRINTLN ("Least common Multiple:" +mincommonmultiple);
Maxcommondivisor=max.getmaxcommondivisor ( -64,48);
System.out.println ("Greatest common divisor:" +maxcommondivisor);
}
catch (Negativeintegerexception e) {
System.out.println (E.tostring ());}
TODO Code application logic here
}
}