View Single Post
Staro 07.04.2011., 15:37   #6
burki
Umalo Premium
 
Datum registracije: Jan 2009
Lokacija: localhost
Postovi: 61
Pa izpisuje stalno referencu na prvi element polja. Šta će ti te reference?! Makni to.

2D polje sam koristio da bih lakše učitao podatke iz datoteke.
Sada možemo ljepše ispisati to na ekran:
Code:
import java.io.*;

class files
{
		public static void main(String[] args)
		{
			try
			{
				char slovo;
				int ii = 0;
				int jj = 0;
				int i = 0;
				int j = 0;
				BufferedReader in  = new BufferedReader(new FileReader("file.txt"));
				String[][] rijec = new String[100][100];
				rijec[0][0] = "";
				
				while((slovo = (char)in.read()) != '&')
				{
					if (slovo == '\n')
					{
						i++;
						rijec[i][j] = "";
					}
					else if (slovo == ' ')
					{
						j++;
						rijec[i][j] = "";
					}
					else
					{
						rijec[i][j] += slovo;
					}
				}
			
				for(ii = 0; ii <= i; ii++)
				{	
					for(jj = 0; jj <= j; jj++)
						if(rijec[ii][jj] != null)System.out.print("\t" + rijec[ii][jj]);
					System.out.println("");
				}	
			}
			catch (Exception e)
			{
				System.err.println("Error: " + e.getMessage());
			}
		}
}
burki je offline   Reply With Quote