Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.FileNotFoundException;
- import java.util.*;
- import java.io.*;
- import java.lang.*;
- public class inputoutput {
- public static void main(String[] args) {
- Formatter output;
- String name;
- int mark = 0;
- Scanner input = new Scanner(System.in);
- try{
- output = new Formatter("Students.txt");
- System.out.print("Enter name: ");
- while(input.hasNext()){
- name = input.next();
- System.out.print("Enter mark: ");
- mark = input.nextInt();
- output.format("%s %d\f\n", name, mark);
- System.out.print("Enter name: ");
- }
- if (output != null){
- output.close();
- }
- } catch(SecurityException se){
- System.out.println("You do not have write access");
- } catch(FileNotFoundException fe) {
- System.out.println("Error opening/creating file.");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment