What is wrong with my code? use the IN300_Dataset2.txt file (https://kapextmediassl-a.akamaihd.net/IST/IN300/IN300_1905A/IN300_Dataset2.txt) Write a Java program that: A. Reads the text file. B. Using that data, create a two-dimensional array that is 2,500 rows by 100 columns. C. Slice the two-dimensional array using a starting column index of 2 and an ending column index of 5. Print the results of the arrays and slice. import java.io.BufferedReader; import java.io.FileNotFoundException; import java.io.FileReader; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.io.File; import java.util.Scanner; import java.lang.Float; public class Main { public static void main(String args[]) { File file = new File("/Users/ahmedgasim/Desktop/IN300_Dataset2.txt"); String line; ArrayList data = new ArrayList(); try (BufferedReader br = new BufferedReader(new FileReader(file))) { while((line = br.readLine())) ! = null) { data.add(Long.parseLong(line)); } } catch (Exception e) { System.out.println(e); } int sRows = 2500; int sCols = 100; int entry = 0; long [][] array2D = new long[Rows][Cols]; for (int r = 0; r < Rows; r++) System.out.print("["); for (int c = 0; c < Cols; c++) { array2D[r][c] = data.get(entry++); System.out.print(array2D[r][c] + ""); } System.out.print("]"); } int sRows = 2500; int sCols = 4; float [][] sliced = new float[sRows][sCols]; for(int sr =0; sr < sRows; sr++) { for (int sc = 0; sc < sCols; sc++) { sliced[sr][sc] = array2D[sr][sc]; } } for (int i = 0; i < sliced.lenght; i++){ for (int j = 0; j < sliced[j].lenght; j++) { System.out.print(sliced[i][j] + ""); } System.out.println(); } }
What is wrong with my code?
use the IN300_Dataset2.txt file (https://kapextmediassl-a.akamaihd.net/IST/IN300/IN300_1905A/IN300_Dataset2.txt)
Write a Java program that:
A. Reads the text file.
B. Using that data, create a two-dimensional array that is 2,500 rows by 100 columns.
C. Slice the two-dimensional array using a starting column index of 2 and an ending column index of 5. Print the results of the arrays and slice.
import java.io.BufferedReader; import java.io.FileNotFoundException; import java.io.FileReader; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.io.File; import java.util.Scanner; import java.lang.Float; public class Main { public static void main(String args[]) { File file = new File("/Users/ahmedgasim/Desktop/IN300_Dataset2.txt"); String line; ArrayList<Long> data = new ArrayList<Long>(); try (BufferedReader br = new BufferedReader(new FileReader(file))) { while((line = br.readLine())) ! = null) { data.add(Long.parseLong(line)); } } catch (Exception e) { System.out.println(e); } int sRows = 2500; int sCols = 100; int entry = 0; long [][] array2D = new long[Rows][Cols]; for (int r = 0; r < Rows; r++) System.out.print("["); for (int c = 0; c < Cols; c++) { array2D[r][c] = data.get(entry++); System.out.print(array2D[r][c] + ""); } System.out.print("]"); } int sRows = 2500; int sCols = 4; float [][] sliced = new float[sRows][sCols]; for(int sr =0; sr < sRows; sr++) { for (int sc = 0; sc < sCols; sc++) { sliced[sr][sc] = array2D[sr][sc]; } } for (int i = 0; i < sliced.lenght; i++){ for (int j = 0; j < sliced[j].lenght; j++) { System.out.print(sliced[i][j] + ""); } System.out.println(); } }
Trending now
This is a popular solution!
Step by step
Solved in 3 steps with 1 images