Jump to content
pnvm

Tabelas

Recommended Posts

pnvm

import java.io.*;

import java.util.*;

public class ReadArrayFile {

public static void main(String[] args) {

String filename = "produtos.txt";

try {

FileReader f = new FileReader(filename);

BufferedReader input = new BufferedReader(f);

String str; //string de linhas do ficheiro

ArrayList<String> fa = new ArrayList<String>(); // criar arraylist fa

/* ciclo leitura ficheiro */

while ((str = input.readLine()) != null) {

fa.add(str);//adicionar linha ao arraylist

}

/* ciclo de output ficheiro */

System.out.println("+------------------------+");

System.out.println("|      a  b  c  d        |");

System.out.println("+------------------------+");

for (int i=0;i<fa.size();i++){

System.out.print("      ");

System.out.println(fa.get(i)+" ");//obter linha do arrylist e imprimir

}

input.close();//terminar o input

} catch (IOException e) {

//e.printStackTrace();

System.out.println("ficheiro "+filename+" nao encontrado");

}

}

}

o print disto sai me

+------------------------+

|      a  b  c  d        |

+------------------------+

      Sabonete,5,10.2;Xupa-Xupa,6,1;Kitt-Kat,1,1.5;Abacate,0,1

      Cromos,10,5.5;Laranjas,2,0.5;Limoes,1,0.5;Rebucado,0,0.5

      Chocolate,1,1;Imans,4,2;Jogo,1,20;Lingerie,10,30;

      Tintas,0,12.5;Atum,9,6.5;Tesoura,0,4.2;Oleos,3,12.5;

      Vidros,4,2;Yogurte,4,1.75;Tiramisu,1,3;Gelado,4,2

gostava se me pudessem ajudar a ficar cada um dos "produtos" debaixo de uma letrae so quando se colhesse e que o preço aparecia....

Share this post


Link to post
Share on other sites
GaaF

o mais facil e crias uma tabela

algo deste estilo

  String s[][] = new String[10][10];

e mandas para o a, b , c e d

e nas respectivas colunas os dados de a, b , c e d

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...

Important Information

By using this site you accept our Terms of Use and Privacy Policy. We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.