1. computes the greatest common divisor of an integer x and an integer y. (not allowed in the way the classroom is used)
① use class and method implementations (define a class, define a method for greatest common divisor in a class), and name it according to the specification.
② gets the two integers entered by the user in the main method, invokes the previously written method, and outputs their greatest common divisor.
③ using FindBugs to find bugs in the program
Code:
Package com.xxxx;
import Java.util.Scanner;
Public class Demo {
void divisor (int x, int y) {
while (x%y! = 0) {
int temp = x% y;
x = y;
y = temp;
}
System. out. println ("Greatest common divisor for:" +y);
}
Public Static void Main (string[] args) {
TODO auto-generated Method stub
Scanner in = new Scanner (System. in);
System. out. Print ("Please enter the first integer:");
int a = In.nextint ();
System. out. Print ("Please enter a second number:");
int b = in.nextint ();
Demo de = New demo ();
De.divisor (A, b);
}
}
Operation diagram:
Use FindBugs to find bugs in your program:
Install FindBugs, run diagram:
"Software Testing" course experiment 3 the first question