Programming Assignment #121
Code
import java.io.PrintWriter;
import java.util.Scanner;
import java.io.IOException;
public class Score{
public static void main(String[] args){
PrintWriter writer;
try{
writer = new PrintWriter("score.txt");
Scanner k = new Scanner(System.in);
System.out.println("You got a high score!");
System.out.println();
System.out.print("Enter your score: ");
int score = k.nextInt();
System.out.print("Enter your name: ");
String name = k.next();
writer.println("Score: " + score);
writer.println("Name: " + name);
writer.close();
System.out.println("Data stored in score.text.");
}
catch(IOException e){
System.exit(0);
}
}
}
Outputs