Advertisement
vinedfs

Escritor de notas

Jul 22nd, 2014
223
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.81 KB | None | 0 0
  1. package br.com.geracao.main;
  2.  
  3. import java.io.File;
  4. import java.io.PrintWriter;
  5.  
  6. import javax.swing.JOptionPane;
  7.  
  8. public class EscritorDeNotas {
  9.  
  10.     public static void main(String[] args) {
  11.        
  12.        
  13.         float[] notas = { 9.5f, 9.2f, 9.2f, 8.5f, 8.2f, 8.0f, 8.0f, 8.0f, 7.7f, 7.6f, 7.4f, 7.2f, 6.8f, 6.2f, 5.1f, 4.6f, 4.6f, 3.8f, 2.5f };
  14.        
  15.         File file = new File("C:\\arquivo.txt");
  16.         try {
  17.             PrintWriter pw = new PrintWriter(file);
  18.             for (int i = 0; i < notas.length; i++) {
  19.                 pw.println(notas[i]);
  20.             }
  21.             pw.close();
  22.             JOptionPane.showMessageDialog(null, "Cadastro realizado com sucesso!");
  23.         } catch (Exception e) {
  24.             JOptionPane.showMessageDialog(null, "Erro ao escrever no arquivo (" + e.getLocalizedMessage() + ").");
  25.         }
  26.        
  27.         JOptionPane.showMessageDialog(null, "Programa finalizado.");
  28.  
  29.     }
  30.  
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement