-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcode_6.java
More file actions
44 lines (32 loc) · 868 Bytes
/
code_6.java
File metadata and controls
44 lines (32 loc) · 868 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
package clong.jgsu;
import java.util.Scanner;
public class code_6 {
public static void main(String[] args) {
/**
* 题目:输入两个正整数m和n,求其最大公约数和最小公倍数。
*/
System.out.println("请输入两个整数:");
Scanner sc = new Scanner(System.in);
int a = sc.nextInt();
int b = sc.nextInt();
int bigDivisor = 0;
int multiple = 0;
int sum = a*b;
int temp = 0;
if(b>a){
temp = a;
a = b;
b = temp;
}
while(temp!=0){
temp = a%b;
a = b;
b = temp;
}
bigDivisor = a;
multiple = sum/bigDivisor;
System.out.println("最大公约数:"+bigDivisor);
System.out.println("最小公倍数:"+multiple);
sc.close();
}
}