Here in my code, I have two String type ArrayList arr and arr2. arr ArrayList is for storing the pair of lines and here int t is for the number of pairs that user enters in arr. The Second ArrayList arr2 is for storing a single line and integer t2 is the number of a single line that a users stores in arr2. After that I have simply print arr and arr2
import java.util.Scanner;
class Main{
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
ArrayList<String> arr = new ArrayList<>();
ArrayList<String> arr2 = new ArrayList<>();
int t;
t = sc.nextInt();
sc.nextLine();
for(int i=0;i<t;i++){
String first,second;
first = sc.nextLine();
second = sc.nextLine();
arr.add(first);
arr.add(second);
}
sc.nextInt();
int t2;
t2 = sc.nextInt();
sc.nextLine();
for(int i=0;i<t2;i++){
String input;
input = sc.nextLine();
arr2.add(input);
}
for(String val: arr){
System.out.println(val);
}
System.out.println();
for(String val: arr2){
System.out.println(val);
}
}
}
But after entering all the input I'm getting Exception in thread "main" java.util.InputMismatchException
Sample Input-
3
ko te kader molla
tui rajakar tui rajakar
tumi ke ami ke
garo chakma bangali
jalo re jalo
agun jalo
2
jalo re jalo
ko te kader molla
Sample Output-
ko te kader molla
tui rajakar tui rajakar
tumi ke ami ke
garo chakma bangali
jalo re jalo
agun jalo
jalo re jalo
ko te kader molla
pairsOfLinesthanarr2.