Advertisement
Guest User

Untitled

a guest
Dec 10th, 2019
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.12 KB | None | 0 0
  1.  
  2. import java.util.*;
  3. import java.io.*;
  4. public class _7_3 {
  5.     static Scanner kb = new Scanner (System.in);
  6.     public static void main (String[] args) throws IOException {
  7.     int x;
  8.     do
  9.     {
  10.         System.out.print ("1-Escolher Ficheiro");
  11.         System.out.print ("2-Adicionar Numeros ao Ficheiro");
  12.         System.out.print ("3-Escrever a sequencia");
  13.         System.out.print ("4- Calcular o maximo da sequencia");
  14.         System.out.print ("5-Calcular o minimo da sequencia");
  15.         System.out.print ("6-Verificar se a sequencia e constituida so por numeros pares");
  16.         System.out.print ("7- Terminar programa");
  17.         x = kb.nextInt ();
  18.         switch (x)
  19.         {
  20.             case 1: double[] sdf = escolher ();
  21.             break;
  22.             case 2: adicionar (sdf);
  23.             break;
  24.             //~ case 3: escrever;
  25.             //~ break;
  26.             //~ case 4 : maximo;
  27.             //~ break;
  28.             //~ case 5: minimo;
  29.             //~ break;
  30.             //~ case 6: pares;
  31.             //~ break;
  32.             //~ case 7: System.out.print ("Programa terminado"),
  33.             //~ System.exit (1);
  34.             //~ break;
  35.         }
  36.        
  37.     } while (x!=7);
  38.      
  39.    
  40.    
  41. }
  42.     public static double [] escolher(){
  43.         int count= 0;
  44.         String name_of_file;
  45.         System.out.print ("Nome do Ficheiro: ");
  46.         name_of_file = kb.nextLine ();
  47.         File my_file = new File (name_of_file);
  48.         Scanner read_from_file = new Scanner (my_file);
  49.        
  50.         if (!my_file.exists ()){
  51.         {
  52.             System.out.println ("Erro: o ficheiro " + name_of_file+ "nao existe!");}
  53.         if (my_file.isDirectory()){
  54.             System.out.println ("Erro: o ficheiro " + name_of_file + "ยดe um diretorio!");}
  55.         if (!my_file.canRead ()){
  56.             System.out.println ("Erro:  nao e possivel ler o ficheiro " + name_of_file );}
  57.         if (my_file.exists ()){
  58.             do{
  59.                 count ++;
  60.         } while (read_from_file.hasNextLine ());}
  61.        
  62.         double [] sdf  = new double [count];
  63.          
  64.         for (int i = 0; i < count; i++)
  65.         {
  66.             double y = read_from_file.nextDouble ();
  67.             sdf [i] = y;
  68.         }
  69.         return sdf;
  70.     }
  71.    
  72.     public static void adicionar (double [] sdf){
  73.         System.out.print ("Quantidade de numeros a adicionar: ");
  74.         int z = kb.nextDouble ();
  75.         int count =0;
  76.         System.out.print ("Numeros a adicionar :");
  77.         do
  78.         {
  79.             double k = kb.nextDouble;
  80.             count ++;
  81.         } while (count<=z);}
  82.     }
  83. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement