Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.FileReader;
- import java.io.FileWriter;
- import java.io.IOException;
- import java.util.Scanner;
- import static java.lang.System.out;
- public class Program {
- public static void type () throws IOException {
- Scanner read = new Scanner(new FileReader("Ships.txt"));
- int n = Integer.parseInt(read.next());
- int m = Integer.parseInt(read.next());
- int[][] array = new int[n][m];
- for (int i = 0; i < n; i++) {
- for (int j = 0; j < m; j++) {
- array[i][j] = Integer.parseInt(read.next());
- }
- }
- out.println("Array from file " + "\n");
- out.println(n + " rows " + m + " columns " + "\n");
- for (int i = 0; i < n; i++) {
- for (int j = 0; j < m; j++) {
- out.print(array[i][j] + " ");
- }
- out.println();
- }
- out.println();
- // int t1 = ( array[n-1][m-1] = 1 );
- // int t2 = ( array[n+1][m] = 1);
- // int t3 = array[n+2][m] = 1;
- // int t4 = array[n+3][m] = 1;
- //
- // int t5 = array[n][m+2] = 1;
- // int t6 = array[n][m+3] = 1;
- // int t7 = array[n][m+4] = 1;
- Scanner uni = new Scanner(System.in);
- out.println("Input coordinats - " + "\n");
- out.println("Row - ");
- int row = uni.nextInt();
- out.println("Column - ");
- int column = uni.nextInt();
- out.println();
- int counter_t1 = 0;
- out.println("Ship have following specs: ");
- 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");
- 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");
- if ( array[(row-1)][(column-1)] == 1 && (array[(row-1)][(column-1)+1]) == 1 ) out.println("Horizontal with length 2 ");
- if ( array[(row-1)][(column-1)] == 1 ) out.println("Length 1 ");
- 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 )
- out.println("Vertical with length 4");
- 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");
- if ( array[(row-1)][(column-1)] == 1 && array[(row-1)+1][(column-1)] == 1 ) out.println("Vertical with length 2");
- /*
- Ships.txt
- 5 6
- 1 1 1 1 0 1
- 0 1 1 0 0 1
- 0 1 0 1 0 1
- 0 0 1 0 0 0
- 1 1 1 1 1 1
- */
- }
- public static void main(String[] args) throws IOException {
- type();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement