3-20java's time

          No matter how ,today's studing is a harvest! first of all,rather than look at the answer of the Algorithm question,i can littlely have thought and in some time .the result turns out myself's idea is more Wisdom,haha.so it is a valuable words:just believe youself without anything else.

          beside the Grammar and Mode,or anything other,using  the java language to solve the question of life and learning and trying to make a better solution is a great enjoy without saying .and it is also a wayto make a difference,in a meaning this can lead to a great difference in the furture sooner or latter.may be do youself best is on the way of trying tomake a difference and enjoy ourself.Great isn't it?!

          in one word ,just do it! I LOVE JAVA!

 ONE OF THE Algorithm:to find the Greatest common divisor of two rand nums;to find the Least common multiple of two rand nums;

 

import java.util.Scanner;

//最小公倍数=积/最大公约数!!!!!!
public class GongyueshuGongbeishu {

 public static void main(String[] args) {
  int[] grade = new int[2];
  int m, n;
  int min;

  Scanner scanner = new Scanner(System.in);
  for (int i = 0; i < 2; i++) {
   grade[i] = scanner.nextInt();
  }
  if (grade[0] > grade[1]) {
   m = grade[0];
   n = grade[1];
  } else {
   n = grade[0];
   m = grade[1];
  }

  int i = 1;
  while (m <= m * n) {

   if ((m * i) % n == 0) {
    System.out.println("最小公倍数:" + m * i);
    System.out.println("最大公约数:" + m * n / (m * i));
    break;
   } else {
    i++;
   }
  }
  int j = 1;
  while (n / j >= 1) {

   if (n % j == 0 && m % (n / j) == 0) {
    System.out.println("最大公约数:" + n / j);
    System.out.println("最小公倍数:" + m * n / (n / j));
    break;
   } else {
    j++;
   }
  }
 }

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值