"Software Testing" course experiment 3 the first question

Source: Internet
Author: User
Tags greatest common divisor

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.