我正在研究此分配,以便从尝试/捕获主要方法中获得一种方法,并在新方法中使用扫描仪和印刷机,以进行此数组读写代码。 但是我一直收到此错误:“编辑器不包含主类型。” 可能是什么原因?
任何帮助表示赞赏,谢谢
(所有扫描仪..等导入这里)
public class Program_11_1
{
public static void main(String[] args)
{
String file_name;
String outputFileName = null;
String done_string = "done";
boolean done = false;
while (!done)
{
file_name = JOptionPane.showInputDialog("Enter a file
name"
+ " or done to exit: ");
if (file_name.equals(done_string))
{
done = true;
JOptionPane.showMessageDialog(null,
"EXITING");
}
else
{
Scanner input = get_Scanner(file_name);
outputFileName = JOptionPane.showInputDialog(null,
"Enter the output file name: ");
PrintWriter output_writer =
get_Writer(outputFileName);
Scanner input_counter =
get_Scanner(file_name);
if ((input != null && output_writer != null &&
input_counter != null))
{
//********TASK
CODE**************
// Use Scanner input_counter
to determine the number of integers
// in
int num_ints =
size(input_counter);
// Create an integer
array of size ; named
int[] int_array =
return_Array(num_ints);
// Read the integers
in into
fill_Array(int_array,
input);
// Sort the integers
in to run from lowest (at [0]
// to highest at
[ - 1]
int ordered_array[] =
order_Array(int_array);
// Write the integers
in the sorted array to
print_Array(ordered_array, output_writer);
//*******END TASK CODE************
}
input.close();
input_counter.close();
output_writer.close();
}
}
}
public static Scanner get_Scanner(String file_name) {
try
{
File file_in = new File(file_name);
Scanner input = new Scanner(file_in);
JOptionPane.showMessageDialog(null, "File " +
file_name + " found ");
return input;
}
catch (FileNotFoundException e) {
JOptionPane.showMessageDialog(null, "File " +
file_name + " not found");
return null;
}
}
public static PrintWriter get_Writer(String out_file_name) {
try
{
PrintWriter output_writer = new
PrintWriter(out_file_name);
JOptionPane.showMessageDialog(null, "created output
file: " + out_file_name);
return output_writer;
}
catch (FileNotFoundException e)
{
JOptionPane.showMessageDialog(null, "output file
FAILED");
return null;
}
}
}
}
(不包括size,return_Array,int_array,order_Array,print_Array方法,这些都可以)