Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.*;
- import java.io.*;
- public class _7_3 {
- static Scanner kb = new Scanner (System.in);
- public static void main (String[] args) throws IOException {
- int x;
- do
- {
- System.out.print ("1-Escolher Ficheiro");
- System.out.print ("2-Adicionar Numeros ao Ficheiro");
- System.out.print ("3-Escrever a sequencia");
- System.out.print ("4- Calcular o maximo da sequencia");
- System.out.print ("5-Calcular o minimo da sequencia");
- System.out.print ("6-Verificar se a sequencia e constituida so por numeros pares");
- System.out.print ("7- Terminar programa");
- x = kb.nextInt ();
- switch (x)
- {
- case 1: double[] sdf = escolher ();
- break;
- case 2: adicionar (sdf);
- break;
- //~ case 3: escrever;
- //~ break;
- //~ case 4 : maximo;
- //~ break;
- //~ case 5: minimo;
- //~ break;
- //~ case 6: pares;
- //~ break;
- //~ case 7: System.out.print ("Programa terminado"),
- //~ System.exit (1);
- //~ break;
- }
- } while (x!=7);
- }
- public static double [] escolher(){
- int count= 0;
- String name_of_file;
- System.out.print ("Nome do Ficheiro: ");
- name_of_file = kb.nextLine ();
- File my_file = new File (name_of_file);
- Scanner read_from_file = new Scanner (my_file);
- if (!my_file.exists ()){
- {
- System.out.println ("Erro: o ficheiro " + name_of_file+ "nao existe!");}
- if (my_file.isDirectory()){
- System.out.println ("Erro: o ficheiro " + name_of_file + "ยดe um diretorio!");}
- if (!my_file.canRead ()){
- System.out.println ("Erro: nao e possivel ler o ficheiro " + name_of_file );}
- if (my_file.exists ()){
- do{
- count ++;
- } while (read_from_file.hasNextLine ());}
- double [] sdf = new double [count];
- for (int i = 0; i < count; i++)
- {
- double y = read_from_file.nextDouble ();
- sdf [i] = y;
- }
- return sdf;
- }
- public static void adicionar (double [] sdf){
- System.out.print ("Quantidade de numeros a adicionar: ");
- int z = kb.nextDouble ();
- int count =0;
- System.out.print ("Numeros a adicionar :");
- do
- {
- double k = kb.nextDouble;
- count ++;
- } while (count<=z);}
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement