Advertisement
Guest User

Krastosloviza

a guest
Oct 7th, 2018
135
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 5 1.50 KB | None | 0 0
  1. package Lesson_08;
  2.  
  3. import java.util.Scanner;
  4.  
  5. public class _05_ {
  6.     public static void main(String[] args) {
  7.         Scanner scan = new Scanner(System.in);
  8.         System.out.print("Add first string : ");
  9.         String[] acrossWord = scan.nextLine().split("");
  10.         System.out.print("Add second string : ");
  11.         String[] downWord = scan.nextLine().split("");
  12.  
  13.         int commonRow = -1;
  14.         int commonCol = -1;
  15.  
  16.         for (int row = 0; row < downWord.length; row++) {
  17.             for (int col = 0; col < acrossWord.length; col++) {
  18.                 if (downWord[row].equals(acrossWord[col])) {
  19.                     commonRow = row;
  20.                     commonCol = col;
  21.                 }
  22.             }
  23.         }
  24.         System.out.println(commonRow);
  25.         System.out.println(commonCol);
  26.  
  27.         if (commonRow == -1) {
  28.             System.out.println("Not have common character.");
  29.         } else {
  30.             for (int currentRow = 0; currentRow < downWord.length; currentRow++) {
  31.                 if (currentRow == commonRow) {
  32.                     for (int j = 0; j < acrossWord.length; j++) {
  33.                         System.out.print(acrossWord[j]);
  34.                     }
  35.                 } else {
  36.                     for (int j = 0; j < commonCol; j++) {
  37.                         System.out.print(" ");
  38.                     }
  39.                     System.out.print(downWord[currentRow]);
  40.                 }
  41.                 System.out.println();
  42.             }
  43.         }
  44.     }
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement