Skip to content

Instantly share code, notes, and snippets.

@bitcpf
Created September 21, 2014 16:56
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 bitcpf/7b984da0cdb9b34de7a5 to your computer and use it in GitHub Desktop.
Save bitcpf/7b984da0cdb9b34de7a5 to your computer and use it in GitHub Desktop.
import java.util.Random;
public class Q9_7 {
public static void Paintfil(char[][] screen, int x, int y, char newcolor, char oldcolor){
if(x < 0 || x > screen[0].length-1 ||
y <0 || y > screen.length-1 || screen[x][y] != oldcolor)
return;
screen[x][y] = newcolor;
Paintfil(screen, x-1,y,newcolor,oldcolor);
Paintfil(screen, x+1,y,newcolor,oldcolor);
Paintfil(screen, x,y-1,newcolor,oldcolor);
Paintfil(screen, x,y+1,newcolor,oldcolor);
}
public static void main(String[] args) {
char[][] screen = new char[6][8];
char[] ColorSet = new char[] { 'R', 'G', 'B' };
Random r = new Random();
for (int i = 0; i < screen.length; i++){
for (int j = 0; j < screen[0].length; j++){
screen[i][j] = ColorSet[Math.abs(r.nextInt()) % ColorSet.length];
}
}
System.out.println("Before Paintfill");
screen[2][4] = 'G';
displayscreen(screen);
System.out.println("After Paintfill");
Paintfil(screen,2,4,'B','G');
displayscreen(screen);
}
private static void displayscreen(char[][] screen) {
// TODO Auto-generated method stub
for(int i = 0; i < screen.length; i ++){
for (int j = 0; j < screen[0].length; j ++)
System.out.print(screen[i][j]+" ");
System.out.println();
}
System.out.println();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment