我目前有一个文本文件如下:
3 5 6 9
3 4 6 7 2
3 5 7 2 5 3
Run Code Online (Sandbox Code Playgroud)
读入java时的文件应显示为3x ^ 5 + 6x ^ 9.第二行将被读作4x ^ 4 + 6x ^ 7 + 2.由于我不知道如何将这些数字转换为该形式,因此无法让我的程序显示.当我运行程序时,我目前只得到它们之间有空格的数字.
这是我尝试过的:
import java.io.File;
import java.io.FileNotFoundException;
import java.util.Scanner;
import javax.swing.JOptionPane;
public class Driver {
public static void main(String[] args) {
try {
@SuppressWarnings("resource")
Scanner myfile = new Scanner(new File("poly.dat"));
Polynomial[] mypolynomial;
mypolynomial = new Polynomial[10];
int index = 0;
if (myfile.hasNext() == true) { //ignore this part
myfile.nextLine();
} else …Run Code Online (Sandbox Code Playgroud)