Java 从文本文件打印到终端和新文本文件中读取数据
我想从文本文件中读取数据,并将输出打印到终端和文本文件。我有一个读取数字的循环和一个读取非数字字符的循环,但是没有任何东西打印到终端。我是编程新手。 顺便说一下,我正在把一个旧项目改造成一个新项目Java 从文本文件打印到终端和新文本文件中读取数据,java,text-files,printwriter,Java,Text Files,Printwriter,我想从文本文件中读取数据,并将输出打印到终端和文本文件。我有一个读取数字的循环和一个读取非数字字符的循环,但是没有任何东西打印到终端。我是编程新手。 顺便说一下,我正在把一个旧项目改造成一个新项目 package studenttester; public class Student { private String name; double quizScore; double quizAverage; private int numQuizzes;
package studenttester;
public class Student
{
private String name;
double quizScore;
double quizAverage;
private int numQuizzes;
String grade;
/**
* Returns the name of a student
*
* @return the name of the student
*/
public Student (String inName)
{
name = inName;
quizAverage = 0;
quizScore = 0;
numQuizzes = 0;
}
public String getName()
{
return name;
}
/**
* Adds a quiz score to the total quiz score of the student
*
* @param score the score of a quiz
*/
void addQuiz(int score)
{
numQuizzes += 1;
quizScore += score;
}
/**
* Returns the total score of all the quizzes combined that student took
*
* @return the value of score
*/
double getTotalScore()
{
return quizScore;
}
/**
* Returns the average score of all the quizzes a student took
*
* @return
*/
double getAverageScore()
{
return quizScore / numQuizzes;
}
}
package studenttester;
import java.io.*;
import java.util.Scanner;
public class StudentTester {
public static void main(String[] args) throws FileNotFoundException
{
System.out.println("Student Name Number of Quizzes Average");
Scanner reader = new Scanner(new File("quizScores.txt"));
String studentName = "", first="", last="";
while (!reader.hasNext("-10"))
{
}
while (reader.hasNextDouble())
{
first = first+reader.next();
studentName = last + first;
}
Student newStudent = new Student(studentName);
while (reader.hasNextDouble() && !reader.hasNext("-10"))
{
System.out.printf("");
}
{
// writer.close;
}
}
}
我猜“红色下划线”意味着编译器错误。
看看你的while循环,它似乎是错的。
试试看
相反。事实上,我最终自己找到了答案。谢谢!我仍然不确定System.out.printf(“”;的配置;。我试着打印出学生的名字,他们参加测验的次数,以及他们在测验中的平均成绩。
while (reader.hasNextDouble() && (!reader.hasNext("-10")))
System.out.printf("");
}
reader.close();