Created
November 4, 2019 21:51
-
-
Save hoganlong/32b0ffad7843daee85b706fe8e329f96 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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