Skip to content

Instantly share code, notes, and snippets.

@hoganlong
Created November 4, 2019 21:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hoganlong/32b0ffad7843daee85b706fe8e329f96 to your computer and use it in GitHub Desktop.
Save hoganlong/32b0ffad7843daee85b706fe8e329f96 to your computer and use it in GitHub Desktop.
import java.io.FileNotFoundException;
import java.util.*;
public class TwoDArray {
public static void main(String[] args) throws FileNotFoundException {
java.io.File file = new java.io.File("2DArray.txt");
Scanner input = new Scanner(file);
int totalRow = 6;
int totalColumn = 7;
int nottaspace = 0;
char[][] chars = new char[totalRow][totalColumn];
while (input.hasNext()) {
String word = input.next();
char[] words = word.toCharArray();
int i = 0;
for (int r = 0; r < words.length; r++) {
for (int c = 0; c < totalColumn; c++) {
if (i < words.length) {
chars[r][c] = words[i] == ' ' ? '+' : words[i];
i++;
nottaspace = 0;
}
else {
if (nottaspace == 0) chars[r][c] = '*';
nottaspace = 1;
}
}
}
for (char[] x : chars) {
System.out.println(Arrays.toString(x));
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment