2D Array HKIS Logo

public class image
public static void main(String []args) {
int[][] hkisLogo= ((** THE HKIS LOGO THAT MR LIN SENT US **))
String[][] replace = new String[hkisLogo.length][hkisLogo[0].length];

for (int row = 0; row < hkisLogo.length; row++){ // goes over every row and changes the value to whatever I want to set it to, loop continues till it reaches every row.
for (int col = 0; col < hkisLogo[row].length; col++){ //goes over every column and changes the specific value to whatever I want it to be
if(hkisLogo[row][col] == 255){ // tells the computer that if it sees 255 in the 2d array, then it should change the value to 00.
replace[row][col] = “00”;
else if (hkisLogo[row][col] == 0){ // tells the computer that if it sees a 0 in the 2d array then it should change it to a space
replace[row][col] = ” “;
System.out.print(replace[row][col]); // tells the computer to print the 2d array with the altered values from the conditional statements above

System.out.println(); // prints the array

In my code, I first wrote a series of two for loops in order to convert and identify values in each and every single one of the rows and columns in the ascii picture that Mr. Lin sent us. After that, I wrote a conditional statements that tells the computer to change every 255 value to a 00, and every 0 to a ‘space.’ This essentially alters the photo to look a little bit different. Finally, I wrote a print statement to print my new and improved picture.

Leave a Reply