i want to write a program that first takes the amount of n and then gets n strings (example: if n = 4 it gets 4 strings ) and then checks all the strings and finds the longest substring that contains in all the strings and prints that substring in the output. and also if we have four strings and such substring exists in 3 of them but does not exist in one of them nothing must be printed but if it exists in all 4 of them it must be printed
example1:
input:
3
asdfg
pysdfgjk
sdfgrty
output:
sdfg
example 2:
3
qwesdj
rioqwe
cbnvmnbml
output:
in example 2 qwe is the longest substring that exists in the first and the second word but it does not exist in the third word so nothing must be printed
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
byte n = input.nextByte();
String[] words = new String[n];
for ( int i = 0 ; i < n ; i++){
words[i]=input.next();
}
}
}
here i get n as input and also get n strings and store them in an array of strings but i do not know how to determine that substring and how to find out if it exists in the strings or not
this should work
Any queries -Please comment