Advertisement
Guest User

Untitled

a guest
Mar 27th, 2020
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.83 KB | None | 0 0
  1. import java.io.FileReader;
  2. import java.io.FileWriter;
  3. import java.io.IOException;
  4. import java.util.Scanner;
  5.  
  6. import static java.lang.System.out;
  7.  
  8.  
  9. public class Program {
  10.  
  11. public static void type () throws IOException {
  12.  
  13. Scanner read = new Scanner(new FileReader("Ships.txt"));
  14.  
  15. int n = Integer.parseInt(read.next());
  16. int m = Integer.parseInt(read.next());
  17.  
  18. int[][] array = new int[n][m];
  19.  
  20. for (int i = 0; i < n; i++) {
  21. for (int j = 0; j < m; j++) {
  22. array[i][j] = Integer.parseInt(read.next());
  23. }
  24. }
  25.  
  26. out.println("Array from file " + "\n");
  27. out.println(n + " rows " + m + " columns " + "\n");
  28.  
  29. for (int i = 0; i < n; i++) {
  30. for (int j = 0; j < m; j++) {
  31. out.print(array[i][j] + " ");
  32. }
  33. out.println();
  34. }
  35. out.println();
  36.  
  37. // int t1 = ( array[n-1][m-1] = 1 );
  38.  
  39. // int t2 = ( array[n+1][m] = 1);
  40. // int t3 = array[n+2][m] = 1;
  41. // int t4 = array[n+3][m] = 1;
  42. //
  43. // int t5 = array[n][m+2] = 1;
  44. // int t6 = array[n][m+3] = 1;
  45. // int t7 = array[n][m+4] = 1;
  46.  
  47. Scanner uni = new Scanner(System.in);
  48.  
  49. out.println("Input coordinats - " + "\n");
  50. out.println("Row - ");
  51. int row = uni.nextInt();
  52. out.println("Column - ");
  53. int column = uni.nextInt();
  54. out.println();
  55.  
  56.  
  57.  
  58. int counter_t1 = 0;
  59.  
  60. out.println("Ship have following specs: ");
  61.  
  62.  
  63.  
  64. if ( array[(row-1)][(column-1)] == 1 && array[(row-1)][(column-1)+1] == 1 && array[(row-1)][(column-1)+2] == 1 && array[(row-1)][(column-1)+3] == 1 ) out.println("Horizontal with length 4");
  65. if ( array[(row-1)][(column-1)] == 1 && array[(row-1)][(column-1)+1] == 1 && array[(row-1)][(column-1)+2] == 1 ) out.println("Horizontal with length 3");
  66. if ( array[(row-1)][(column-1)] == 1 && (array[(row-1)][(column-1)+1]) == 1 ) out.println("Horizontal with length 2 ");
  67. if ( array[(row-1)][(column-1)] == 1 ) out.println("Length 1 ");
  68.  
  69. if ( array[(row-1)][(column-1)] == 1 && array[(row-1)+1][(column-1)] == 1 && array[(row-1)+2][(column-1)] == 1 && array[(row-1)+3][(column-1)] == 1 )
  70. out.println("Vertical with length 4");
  71. if ( array[(row-1)][(column-1)] == 1 && array[(row-1)+1][(column-1)] == 1 && array[(row-1)+2][(column-1)] == 1 ) out.println("Vertical with length 3");
  72. if ( array[(row-1)][(column-1)] == 1 && array[(row-1)+1][(column-1)] == 1 ) out.println("Vertical with length 2");
  73.  
  74. /*
  75. Ships.txt
  76.  
  77. 5 6
  78. 1 1 1 1 0 1
  79. 0 1 1 0 0 1
  80. 0 1 0 1 0 1
  81. 0 0 1 0 0 0
  82. 1 1 1 1 1 1
  83.  
  84. */
  85.  
  86.  
  87. }
  88.  
  89. public static void main(String[] args) throws IOException {
  90.  
  91. type();
  92.  
  93. }
  94.  
  95.  
  96. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement