
Concept explainers
I need some helping fixing my code for this method(in screenshot). Also could you explain tokens please!
public static double[][] readFile (java.io.File file) throws FileNotFoundException{
String[] temp = new String[10];
int row = 0;
int colum = 0;
int i = 0;
int k = 0;
double[][] Fill = null;
Scanner sc;
try {
sc = new Scanner(file);
String[] token;
while(sc.hasNextLine()){
temp[row] = sc.nextLine();
//split = line.split(" ");
row++;
}
Fill = new double[row][];
for(; i<row; i++){
token = temp[i].split(" ");
colum = token.length;
Fill[i] =new double[colum];
for(; k<token.length; k++) {
Fill[i][k]=Double.parseDouble(token[k]);
}
k = 0;
i++;
}
sc.close();
for(int p = 0; p<Fill.length;p++)
{
for(int v =0; v<Fill[colum].length; v++)
{
System.out.println(Fill[row][colum]+ " ");
}
System.out.println();
}
}catch( FileNotFoundException e) {
e.getMessage();
}
return Fill;
}
}
![Method Detail
readFile
public static double[][] readFile (java.io. File file)
throws java.io.FileNotFoundException
Reads from a file and returns a ragged aray of doubles The maximum rows is 10 and the maximum columns for each row is 10
Each row in the file is separated by a new line Each element in the row is separated by a space Suggestion: You need to know how
many rows and how many columns there are for each row to create a ragged array. 1. Read the doubles from the file into an a
temporary array [10][10] of Strings which was initialized to nulls. 2. Find out how many rows there are (any row that has the first
element != null is a valid row) 3. Create the array based on the num of rows, i.e. double[][(Jarray = new double[#rows][] 4.
Determine the number of columns for the first row (any element != null is a valid element) 5. Create the first row, i.e. array[0] =
new double[#columns] 6. Put the values from the temporary array into in the row (don't forget to convert from strings to doubles)
7. Repeat for all rows
Parameters:
file - the file to read from
Returns:
a two dimensional ragged (depending on data) array of doubles if the file is not empty, returns a null if file is empty
Throws:
java.io.FileNotFoundException](https://content.bartleby.com/qna-images/question/8dba62d3-bab9-4b64-b137-060444d690d6/5eabb990-77fe-48b9-8080-32d1ec72b8c1/2qh91am.png)

Trending nowThis is a popular solution!
Step by stepSolved in 2 steps with 2 images

- Please help me using java. I am not understanding why I am getting errorsarrow_forwardIm 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…arrow_forwardWrite a program called Words that: prints your name followed by three asterisks; reads the words in a text file into a String array, where each array entry contains a word; prints the number of words in the file; counts and prints the number of five-letter words; prints all of the five-letter words starting with a vowel (that is, 'a', 'e', 'i', 'o', or 'u'); finds and prints the alphabetically first five-letter word and the alphabetically last five-letter word. it was the best of times it was the worst of timesit was the age of wisdom it was the age of foolishnessit was the epoch of belief it was the epoch of incredulityit was the season of light it was the season of darknessit was the spring of hope it was the winter of despairwe had everything before us we had nothing before uswe were all going direct to heaven we were all going directthe other wayin short the period was so far like the presentperiod that some of its noisiest authorities insisted on itsbeing received for good or…arrow_forward
- Here is the question: Write an application that counts the total number of spaces contained in a quote entered by the user. Here is the code given: import java.util.*; public class CountSpaces2 { public static void main(String[] args) { // Write your code here } }arrow_forwardWrite a program called FiveLetterWords that: prints your name followed by three asterisks; reads the words in a text file into a String array, where each array entry contains a word; prints the number of words in the file; counts and prints the number of five-letter words; prints all of the five-letter words starting with a vowel (that is, 'a', 'e', 'i', 'o', or 'u'); finds and prints the alphabetically first five-letter word and the alphabetically last five-letter word. tale.txt file content : it was the best of times it was the worst of timesit was the age of wisdom it was the age of foolishnessit was the epoch of belief it was the epoch of incredulityit was the season of light it was the season of darknessit was the spring of hope it was the winter of despairarrow_forwardIn java, without Arrays and using only String methods ( don't use String builder) // Question 17: In MS-DOS, a file name consists of up // to 8 characters (excluding '.', ':', backslask, '?', // and '*'), followed by an optional dot ('.' character) // and extension. The extension may contain zero to three // characters. For example, 1STFILE.TXT is a valid filename. // Filenames are case-blind. // // Write and test a method that takes // in a String, validates it as a valid MS-DOS file // name, appends the extensions ".TXT" if no extension // is given (that is, no '.' appears in FILENAME), converts // the name to uppercase, and returns the resulting string // to the calling method // If fileName ends with a dot, remove that dot and do not // append the default extension. If the name is invalid, // validFileName should return null. public String validFileName(String n) { }arrow_forward
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education





