This while loop just loops forever. I looked up solutions and attempted to add something that consumes the input, however this did not help. The printf "readDONEZO" is not printed.
Here is my code
public void read(Scanner stdin) {
int sRow = 0;
while ( stdin.hasNextLine() ) {
String theLine = stdin.nextLine();
String[] split = theLine.split(",");
int size = split.length; //how many values in array = 3
for(int i = 0; i < size ; i++){
String value = split[i];
int sColumn = i;
setCellValue(sRow, sColumn, value);
System.out.printf("%s", getCellValue(sRow,sColumn));
if (i+1 != size) {
System.out.printf(",");
}
}
sRow += 1;
System.out.printf("\n");
}
System.out.printf("readDONEZO\n");
}
Main
import java.io.*;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
int rows = 100;
int columns = 26;
StringSpreadsheet a = new StringSpreadsheet(rows, columns);
Scanner stdin = new Scanner(System.in);
a.read(stdin);
System.out.printf("out of read\n");
a.write();
}
}
Class
import java.util.Scanner;
public class StringSpreadsheet {
private int rows;
private int columns;
private String[][] cells;
private int allRows;
private int allColumns;
public StringSpreadsheet(int rows, int columns) {
allColumns = 0;
allRows = 0;
this.rows = rows;
this.columns = columns;
cells = new String[this.rows][this.columns];
}
public void read(Scanner stdin) {
while ( stdin.hasNextLine() ) {
String theLine = stdin.nextLine();
String[] split = theLine.split(",");
allColumns = split.length; //how many values in array = 3
for(int i = 0; i < allColumns ; i++){
String value = split[i];
int sColumn = i;
setCellValue(allRows, sColumn, value);
System.out.printf("%s", getCellValue(allRows,sColumn));
if (i+1 != allColumns) {
System.out.printf(",");
}
}
allRows += 1;
System.out.printf("\n");
}
System.out.printf("readDONEZO\n");
}
public void write() {
for (int i = 0 ; i < allRows ; i++){
for(int j = 0 ; j < allColumns ; j++){
String value = getCellValue(i, j);
if ()
System.out.printf("%s,", value);
}
}
}
public String getCellValue(int gRow, int gColumn) {
return cells[gRow][gColumn];
}
public void setCellValue(int sRow, int sColumn, String value) {
cells[sRow][sColumn] = value;
}
}