Good day!
There is the following task shown in the picture: It is necessary to create an array of masks for each element entered from the keyboard. for character # = this is 1, for character. this is 0.
From the keyboard, we enter the following sequence:
Input Format: #...# ..... #.... ..... Next you need to get the array shown in the image.
The problem is that when you try to read a row, after reading the first row, we get an array
[1,0,0,0,1] Further, when reading the second line, we should get an array
[01,00,00,01] at the third reading
[101,000,000,001] and at the fourth
[0101,0000,0000,0001] But in reality, we do not add data to the cell of the array, but rewrite it every time we read the data.
byte[] maskArray; Scanner sc = new Scanner(System.in); maskArray = new byte[5]; for(int j=0;j<4;j++){ String s; if(s.charAt(i) == '#') { byte num = 1; byte a = maskArray[i]; byte c = (byte) (a + num); maskArray[i] = c; }else if (s.charAt(i)=='.'){ System.out.print("0"); byte num = 0; byte a = maskArray[i]; byte c = (byte) (a + num); maskArray[i] = c; } } } I understand that I may be doing wrong, and this is most likely the case, but they set the task to sort out this issue, but there is no Java skills, only with javascript.
I would be grateful for the help.
Have a nice day, everyone!
