public class GreatestCommonDivisor
{
String s2 = new String();
int number1,number2,number3;
int s1,p,r;
int[] array1 = new int[20];
int[] array = new int[20];
public void reader()throws IOException
{
//GreatestCommonDivisor check = new GreatestCommonDivisor();
BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream("MAXnumber.txt")));
s1 = Integer.parseInt(br.readLine());
for(int i = 0; i < s1; i++)
{
s2 = br.readLine();
number3 = s2.indexOf(" ");
number1 = Integer.parseInt(s2.substring(0,number3));
number2 = Integer.parseInt(s2.substring(number3 + 1));
p = number1 * number2;
while(number2 != 0)
{
r = number1 % number2;
number1 = number2;
number2 = r;
}
p = p / number1;
System.out.println("最大公约数是:" + number1);
System.out.println("最小公倍数是:" + p);
array[i] = number1;
array1[i] = p;
}
br.close();
}
public void write()throws IOException
{
BufferedWriter rt=new BufferedWriter(new OutputStreamWriter(new FileOutputStream("Answer.txt")));
for(int i = 0;i<s1;i++)
{
rt.write(array[i]);
rt.write(";");
rt.write(array1[i]);
rt.newLine();
}
rt.flush();
rt.close();
System.out.println("写入完毕");
}
public static void main(String args[])throws Exception
{
GreatestCommonDivisor check = new GreatestCommonDivisor();
check.reader();
check.write();
}
}
我上面的程序没有错误可以运行 但是我写入文件的东西为什么是乱码```