Were usng DrRacket in class The famous computer scientist Ed

We\'re usng DrRacket in class.

The famous computer scientist, Edsger Dijkstra, made the
following observations for m and n >= 1:

1. If m = n, then the greatest common divisor of m and n is m.
2. If m > n, then the greatest common divisor of m and n is
   the greatest divisor of m-n and n.

Based on these observations, implement a function to compute
the greatest common divisor of two given numbers >= 1. Follow
all the steps of the design recipe. and write the termination argument and check-expect.

Solution

solution

1)if m=n

import java.util.Scanner;

public class ExceptionTest {
   private static Test test=new Test();

   public static void main(String[] args) {
      
Scanner scanner=new Scanner(System.in);
System.out.println(\"enter the m value\");
int m=scanner.nextInt();
System.out.println(\"enter n value\");
int n=scanner.nextInt();
divison(m,n);
  
       }

   private static void divison(int m, int n) {

       int divisor=0;
       for(int i=1;i<=m;i++)
       {
           if((m%i)==0)
           {
               divisor=i;
               System.out.println(\"the divisor of m is\"+divisor);
           }
          
       }
       System.out.println(\"----------------------------\");
      
       int divisor1=0;
       for(int i=1;i<=n;i++)
       {
           if((n%i)==0)
           {
               divisor1=i;
               System.out.println(\"the divisor of n is\"+divisor1);
           }
          
       }

   }
}

output

created
enter the m value
10
enter n value
10
the divisor of m is1
the divisor of m is2
the divisor of m is5
the divisor of m is10
----------------------------
the divisor of n is1
the divisor of n is2
the divisor of n is5
the divisor of n is10

----------------------------------------------------------------------------------------------------------------------------------------

2)if(m>n)

output

enter the m value
120
enter n value
55
the divisor of m is1
the divisor of m is2
the divisor of m is3
the divisor of m is4
the divisor of m is5
the divisor of m is6
the divisor of m is8
the divisor of m is10
the divisor of m is12
the divisor of m is15
the divisor of m is20
the divisor of m is24
the divisor of m is30
the divisor of m is40
the divisor of m is60
the divisor of m is120
----------------------------
the divisor of n is1
the divisor of n is5
the divisor of n is11
the divisor of n is55

We\'re usng DrRacket in class. The famous computer scientist, Edsger Dijkstra, made the following observations for m and n >= 1: 1. If m = n, then the greate
We\'re usng DrRacket in class. The famous computer scientist, Edsger Dijkstra, made the following observations for m and n >= 1: 1. If m = n, then the greate

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site