3-20java's time

来源:互联网 发布:赢时胜期货软件下载 编辑:程序博客网 时间:2024/06/06 14:15

          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++;
   }
  }
 }

}