fork(2) download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6.  
  7. /* Name of the class has to be "Main" only if the class is public. */
  8. class Ideone
  9. {
  10. static void rasterizeLine(boolean[][] img, int x1, int y1, int x2, int y2) {
  11.  
  12.  
  13. int dy = y2-y1;
  14. int dx = x2-x1;
  15.  
  16. double k = (double) dy / dx;
  17. double y = y1;
  18.  
  19. for( double x = x1; x <= x2; x++ ){
  20. img[(int)Math.round(y)][(int)x] = true;
  21. y = y1 + k;
  22. }
  23.  
  24. }
  25.  
  26. public static void main (String[] args) throws java.lang.Exception
  27. {
  28. boolean[][] img = new boolean[11][11];
  29. rasterizeLine(img, 0, 0, 10, 10);
  30.  
  31. for (int y = 0; y < img.length; ++y) {
  32. for (int x = 0; x < img[0].length; ++x) {
  33. System.out.print(img[y][x] ? "O" : ".");
  34. }
  35. System.out.println();
  36. }
  37. // your code goes here
  38. }
  39. }
Success #stdin #stdout 0.06s 2841600KB
stdin
Standard input is empty
stdout
O..........
.OOOOOOOOOO
...........
...........
...........
...........
...........
...........
...........
...........
...........