Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

How to do an array in java? I need to make an array that reads the latitude and

ID: 3641129 • Letter: H

Question

How to do an array in java?
I need to make an array that reads the latitude and longitude.
A for loop that reads into all of them into the array.

latitude Longitude
27.03434 -73.3423
27.02342 -73.2466
........... ...........
........... ...........
...this continues on
So I guess I need an array to read in the rows from the file without knowing the exact number of rows in the file.

double[][] numbers = new double [][];

for (double row = 0; row < numbers.length; row++)
{
for (double col = 0; col < numbers[row].length; col++)
System.out.println(numbers[row][col]);

Can you please help me. This won't work.


I have tried many ways, but can't figure it out.
There are two columns, but the rows of the files are a lot, and I need the array to read the numbers in the rows that are available into the array

Explanation / Answer

Following Program Reads the Latitude and Longitude from a file called latlong.txt Create a file called latlong.txt and keep it in your project folder. Latitude and longitude are read from file and stored dynamically in a double dimensional array. And print the values in from the double dimensional array. File can have any no of rows. Please find below the following program. import java.io.FileReader; import java.io.LineNumberReader; public class LatLong { public static void main(String[] args) { try { FileReader fr = new FileReader("latlong.txt"); LineNumberReader lr = new LineNumberReader(fr); int count = 0; while (lr.readLine() != null) { count++; } System.out.println("No of lines in the file "+ count); String[][] latlong = new String[count][2]; String line; String[] strarr; FileReader fr1 = new FileReader("latlong.txt"); LineNumberReader lr1 = new LineNumberReader(fr1); // print array in rectangular form int i = 0; while ((line = lr1.readLine()) != null) { strarr = line.split(" "); latlong[i][0] = strarr[0]; latlong[i][1] = strarr[1]; i++; } System.out.println("Latitude Longitude"); for (int j = 0; j
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote