I got this question and I would like to do this kind of program. I have written some codes but already have two problems. Public grid {public grid} {} public grid (element e) {}}
ex>
Element:
public square element {final integer INVISIBLE = 0; Final distance EMPTY = 1; Final FIR FIRST_LETTER = 2; Final integer OTHER_LETTER = 3; Private Ent State; Private string letter; Public element () {} // empty block public element (int state) {this ("", 0); } // filled block public element (string s, int state) {this.state = state; This.letter = s; } Public steady zero changes: st (ints) {} public int getState () {return status; } Public boolean par lang () {return true; } Public boolean par () {back true; } @ Override public string to string () {return "[" + + letter + "]"; }}
Main:
import java.util.Scanner; Public class main {public static zero main (string [] args) {scanner sc = new scanner (System.in); System.out.println ("Height:"); While (Sc.hasNextInt ()) {System.out.println ("int, please!"); Sc.next (); } Final integer height = sk. Next (); Grid [] game = new grid [height]; (Int i = 1; i & lt; = height; i ++) for {string; Tax {system.out.println ("length" + i + ", please!"); S = sc.next (); } While (s.length ()! = I); Element [] line = new element [s.length () + 1]; Element Single = Null; String [] temp = null;
// issue here
temp = s.split (""); System.out.println ("s.length:" + s.length ()); System.out.println ("temp.length:" + temp.length); (String str: temp) {System.out.println ("str:" + str) for //
; } For (int k = 0; k & lt; temp.length; k ++) {if (k == 0) {single = new element (temp [k], 2); System.out.println ("Single 1:" + Single); } And {single = new element (temp [k], 3); System.out.println ("Single 2:" + Single); } Line [k] = single; } (Element L: line) {System.out.println ("Line:" + l); }
// issue here
game [i] = queue; }
//
for (grid g: game) {system.out.println ( G); }}}
and sample output for debug:
height: 3 length 1, please! A.S. Length: 1 Temporary Long: 2 str: str: a single 1: [] Single 2: [A] line: [] row: [A]
Here's what I think should work like Hold a word from the user next to grid element for the whole game, then for each line I said that element [] is called a line. I divided the given text and this is the first problem because string.split () adds a white space? You can clearly see in the output that it has been added for no reason. How can I get rid of it (now I had to add the +1 in line length to run the code). Continuous I am throwing the split text in a temporary string array and with each letter I make the element object and put it into the line array. It looks fine except for the production of this empty space but the next problem is with the grid I have created the creator as an argument, but still I do not have the line as the grid [] elements due to the 'incompatible type' Can throw How can I fix that ? Am I doing this right? Maybe I should get rid of the line as Element [] and simply grid [] []?
P> Why does white space connect?
You must specify a non-empty regular expression as follows:
for (string t: s.split ("")) { System.out.println (t); }
Comments
Post a Comment