m trying ro read a csv file and store it into a 2d array but im getting an error when I run my java code. my csv file contains 69 lines of data Below is my code: import java.util.Scanner; import java.util.Arrays; import java.util.Random; import java.io.File; import java.io.FileNotFoundException; import java.io.FilenameFilter; public class CompLab2 { public static String [][] getEarthquakeDatabase (String Filename) { //will read the csv file and convert it to a string 2-d array String [][] Fileinfo = new String [69][22]; int counter = 0; File file = new File(Filename); try { Scanner scnr = new Scanner(file); scnr.nextLine(); //skips the label in the first row of the file while (scnr.hasNextLine()) { // this while loop will count the number of values in the usgs file counter += 1; // increases by one each time a line is read scnr.nextLine(); } while (scnr.hasNext()) { // reads through csv file while there is a line of data String data = scnr.nextLine(); String[] values = data.split(","); // splits the data at the commas double closingValue = Double.parseDouble(values[4]); System.out.println(values[4]); // prints the data at element 5 } scnr.close(); // closes the scanner } catch (FileNotFoundException e) { //throws exception if file is not found e.printStackTrace(); } return Fileinfo; } public static void main(String[] args) { String nameOfFile = "query(2).csv"; //stores the csv file in a string String [][] earthquakeDatabase = getEarthquakeDatabase (nameOfFile); // creates 2d string array thats equal to method getEarthquakeDatabase System.out.println("Expected number of rows: 69"); System.out.println("Number of rows from the array: " +earthquakeDatabase); double [] earthquakeValues = getEarthquakeValues(earthquakeDatabase); } }
m trying ro read a csv file and store it into a 2d array but im getting an error when I run my java code. my csv file contains 69 lines of data Below is my code: import java.util.Scanner; import java.util.Arrays; import java.util.Random; import java.io.File; import java.io.FileNotFoundException; import java.io.FilenameFilter; public class CompLab2 { public static String [][] getEarthquakeDatabase (String Filename) { //will read the csv file and convert it to a string 2-d array String [][] Fileinfo = new String [69][22]; int counter = 0; File file = new File(Filename); try { Scanner scnr = new Scanner(file); scnr.nextLine(); //skips the label in the first row of the file while (scnr.hasNextLine()) { // this while loop will count the number of values in the usgs file counter += 1; // increases by one each time a line is read scnr.nextLine(); } while (scnr.hasNext()) { // reads through csv file while there is a line of data String data = scnr.nextLine(); String[] values = data.split(","); // splits the data at the commas double closingValue = Double.parseDouble(values[4]); System.out.println(values[4]); // prints the data at element 5 } scnr.close(); // closes the scanner } catch (FileNotFoundException e) { //throws exception if file is not found e.printStackTrace(); } return Fileinfo; } public static void main(String[] args) { String nameOfFile = "query(2).csv"; //stores the csv file in a string String [][] earthquakeDatabase = getEarthquakeDatabase (nameOfFile); // creates 2d string array thats equal to method getEarthquakeDatabase System.out.println("Expected number of rows: 69"); System.out.println("Number of rows from the array: " +earthquakeDatabase); double [] earthquakeValues = getEarthquakeValues(earthquakeDatabase); } }
Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
Related questions
Question
Im trying ro read a csv file and store it into a 2d array but im getting an error when I run my java code. my csv file contains 69 lines of data
Below is my code:
import java.util.Scanner;
import java.util.Arrays;
import java.util.Random;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FilenameFilter;
public class CompLab2 {
public static String [][] getEarthquakeDatabase (String Filename) { //will read the csv file and convert it to a string 2-d array
String [][] Fileinfo = new String [69][22];
int counter = 0;
File file = new File(Filename);
try {
Scanner scnr = new Scanner(file);
scnr.nextLine(); //skips the label in the first row of the file
while (scnr.hasNextLine()) { // this while loop will count the number of values in the usgs file
counter += 1; // increases by one each time a line is read
scnr.nextLine();
}
while (scnr.hasNext()) { // reads through csv file while there is a line of data
String data = scnr.nextLine();
String[] values = data.split(","); // splits the data at the commas
double closingValue = Double.parseDouble(values[4]);
System.out.println(values[4]); // prints the data at element 5
}
scnr.close(); // closes the scanner
} catch (FileNotFoundException e) { //throws exception if file is not found
e.printStackTrace();
}
return Fileinfo;
}
public static void main(String[] args) {
String nameOfFile = "query(2).csv"; //stores the csv file in a string
String [][] earthquakeDatabase = getEarthquakeDatabase (nameOfFile); // creates 2d string array thats equal to method getEarthquakeDatabase
System.out.println("Expected number of rows: 69");
System.out.println("Number of rows from the array: " +earthquakeDatabase);
double [] earthquakeValues = getEarthquakeValues(earthquakeDatabase);
}
}
Expert Solution

This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
This is a popular solution!
Trending now
This is a popular solution!
Step by step
Solved in 2 steps

Recommended textbooks for you

Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON

Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science

Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning

Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON

Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science

Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning

Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning

Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education

Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY