大佬们求解答,java
代码:
package com.hmall;
/**
* @ClassName Test3
* @Description TODO
* @Author dell
* @Date 2019/6/25 16:05
* @Version 1.0
**/
import java.io.*;
import java.text.SimpleDateFormat;
import java.util.Calendar;
public class Test3 {
// 最大公约数
public static int get_gcd(int a, int b) {
int max, min;
max = (a > b) ? a : b;
min = (a < b) ? a : b;
if (max % min != 0) {
return get_gcd(min, max % min);
} else
return min;
}
// 最小公倍数
public static int get_lcm(int a, int b) {
return a * b / get_gcd(a, b);
}
public static void main(String args[]) throws Exception {
//下面传入自己桌面的路径:单斜杠要转义为双斜杠
BufferedReader br = new BufferedReader(new FileReader("C:\\Users\\dell\\Desktop\\test.txt"));
String line = null;
Integer a = Integer.valueOf(br.readLine());
Integer b = Integer.valueOf(br.readLine());
Integer gcd = get_gcd(a, b);
Integer lcm = get_lcm(a, b);
File file = new File("C:\\Users\\dell\\Desktop\\你的学号和姓名.txt");
BufferedWriter bw = null;
try {
bw = new BufferedWriter(new FileWriter(file));
bw.write("最大公约数:" + gcd);
bw.newLine();
bw.write("最小公倍数" + lcm);
bw.newLine();
SimpleDateFormat format = new SimpleDateFormat("yyyy年MM月dd日HH时mm分");
String time = format.format(Calendar.getInstance().getTime());
bw.write("当前时间" + time);
bw.newLine();
bw.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
结果:
2024-08-21 广告