当前位置:网站首页>Title: enter two positive integers m and N to find their maximum common divisor and minimum common multiple
Title: enter two positive integers m and N to find their maximum common divisor and minimum common multiple
2022-06-30 05:54:00 【A bowl of noodles from the landlady】
public class Demo1 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println(" Please enter the first positive integer :");
int i1 = sc.nextInt();
System.out.println(" Please enter the second positive integer :");
int i2 = sc.nextInt();
// Find the greatest common divisor
int min=i1>i2?i2:i1;
for (int i=min;i>=1;i--){
if ((i1%i == 0) && (i2%i ==0)){
System.out.println(" The greatest common divisor is :"+i);
break;
}
}
// Minimum common multiple
int max=i1>i2?i1:i2;
for (int i=max;i<=i1*i2;i++){
if (i%i1==0 && i%i2==0){
System.out.println(" The minimum common multiple is :"+i);
break;
}
}
}
}
边栏推荐
- D. Big Brush
- Rotating frame target detection mmrotate v0.3.1 training dota data set (II)
- Did you know that WPS can turn on eye protection mode?
- Attempt to redefine 'timeout' at line 2 solution
- [openstack]-01- basic introduction
- 聲網,站在物聯網的“土壤”裏
- [Blue Bridge Road -- bug free code] analysis of AT24C02 storage code
- Acwing winter vacation daily question 2022 punch in day 11
- Shenzhou ares tx6 boot logo modification tutorial
- 86. separate linked list
猜你喜欢
How to create a CSR (certificate signing request) file?
强烈推荐十几款IDEA开发必备的插件
Leetcode56. consolidation interval
inno setup 最简单的自定义界面效果
MySQL日志管理、数据备份、恢复
Lantern Festival | maoqiu technology and everyone "guess riddles and have a good night"
English grammar_ Adjective / adverb Level 3 - superlative
STM32F103 series controlled OLED IIC 4-pin
Database SQL language 03 sorting and paging
Sword finger offer 18 Delete the node of the linked list
随机推荐
Codeforces B. MEX and Array
Leader: who can use redis expired monitoring to close orders and get out of here!
What are membrane stress and membrane strain
You don't know how to deduce the location where HashSet stores elements?
声网,站在物联网的“土壤”里
VLAN access mode
Database SQL language 06 single line function
Codeforces Round #390 (Div. 2) D. Fedor and coupons
网络基础知识
Solidity - Security - reentrancy attack
Inno setup the simplest user-defined interface effect
【LeetCode】236. Nearest common ancestor of binary tree
Dynamic programming -- gliding wing of the strange thief Kidd
【板栗糖GIS】global mapper—如何把栅格的高程值赋予给点
[Blue Bridge Road -- bug free code] analysis of AT24C02 storage code
2022年,谁在推动音视频产业的新拐点?
Sword finger offer 18 Delete the node of the linked list
STM32F103系列控制的OLED IIC 4针
Database SQL language 04 subquery and grouping function
Create priority queue