HDU OJ 1108

我与影子孤独终老i 提交于 2020-02-03 21:35:00

HDU OJ 1108
题目如下:
A - 最小公倍数
Input
输入包含多组测试数据,每组只有一行,包括两个不大于1000的正整数.
Output
对于每个测试用例,给出这两个数的最小公倍数,每个实例输出一行。
Sample Input
10 14
Sample Output
70

import java.util.Scanner;
public class Main {
    public static void main(String[] args){
        Scanner sc=new Scanner(System.in);
        while(sc.hasNextInt()){
            int a=sc.nextInt();
            int b=sc.nextInt();
            int s=0;
            if(a>b){
                int temp=b;
                b=a;
                a=temp;
            }
            for(int i=a;i<=a*b;i++) {

                if ((i % a == 0) && (i % b == 0)) {
                    s = i;
                    break;
                }
            }
            System.out.println(s);
        }
    }

}

1:交换变量值(a,b)的方法:
(1)使用第三个变量交换:
temp=a;
a=b;
b=temp;
(2)使用异或交换:
a=a^b
b=a^b
a=a^b

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!