Leejiaxin

Lab 3.3 Input

Apr 15th, 2018
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.82 KB | None | 0 0
  1. import java.io.FileNotFoundException;
  2. import java.util.*;
  3. import java.io.*;
  4. import java.lang.*;
  5.  
  6. public class inputoutput {
  7.  
  8.     public static void main(String[] args) {
  9.        
  10.         Formatter output;
  11.         String name;
  12.         int mark = 0;
  13.        
  14.         Scanner input = new Scanner(System.in);
  15.        
  16.         try{
  17.             output = new Formatter("Students.txt");
  18.             System.out.print("Enter name: ");
  19.             while(input.hasNext()){
  20.                 name = input.next();
  21.                 System.out.print("Enter mark: ");
  22.                 mark = input.nextInt();
  23.                 output.format("%s %d\f\n", name, mark);
  24.                 System.out.print("Enter name: ");
  25.             }
  26.             if (output != null){
  27.                 output.close();
  28.             }
  29.         } catch(SecurityException se){
  30.             System.out.println("You do not have write access");
  31.         } catch(FileNotFoundException fe) {
  32.             System.out.println("Error opening/creating file.");
  33.         }
  34.  
  35.     }
  36.  
  37. }
Advertisement
Add Comment
Please, Sign In to add comment