import java.io.*;
import java.util.*;
class Permutation {
static void combinationUtil(int arr[], int n, int r, FileWriter out, int index,int data[], int i)
{
if (index == r)
{
for (int j=0; j<r; j++)
out.print(data[j]+" ");
out.println(" ");
return;
}
if (i >= n)
return;
data[index] = arr[i];
combinationUtil(arr, n, r, out, index+1, data, i+1);
combinationUtil(arr, n, r, out, index, data, i+1);
}
static void printCombination(int arr[], int n, int r, FileWriter out)
{
int data[]=new int[r];
combinationUtil(arr, n, r,out, 0, data, 0);
}
public static void main (String[] args) {
File file = new File("output.txt");
file.createNewFile();
FileWriter out = new FileWriter(file);
int arr[] = {1, 2, 3, 4, 5, 6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28};
int r = 6;
int n = arr.length;
printCombination(arr, n, r, out);
out.flush();
out.close();
}//end main
}//end calss
C:\Users\Student\Documents\Permutation.java:21: error: cannot find symbol out.print(data[j]+" "); ^ symbol: method print(String) location: variable out of type FileWriter 1 error
过程完成。 有问题可以纠正此错误帮助。我尝试使用单独的函数传递它,但它没有工作。
系统工作正常,如果我想在屏幕上显示结果,但我想要做的是将输出写入文本文件。问题中的“out”来自PrintWriter out(一个变量)。 – user8377612
如果我想在屏幕上显示结果,System.out.print可以工作。我想要做的是将结果写入输出文件“output.txt”。 – user8377612