-
Notifications
You must be signed in to change notification settings - Fork 0
/
number_of_grandchildrn.java
37 lines (35 loc) · 1.02 KB
/
number_of_grandchildrn.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
/*
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
*/
package zoho;
import java.util.*;
/**
*
* @author USER
*/
public class number_of_grandchildrn {
public static void main(String[] args)
{
Scanner c = new Scanner(System.in);
int m=c.nextInt();
String[][] f = new String[m][2];
int cnt=0;
ArrayList<String> p = new ArrayList<String>();
for(int i=0;i<m;i++)
for(int j=0;j<2;j++)
f[i][j]=c.next();
System.out.println("Enter GrandParent name: ");
String gp = c.next();
for(int i=0;i<m;i++)
{
if(f[i][1].equals(gp)) p.add(f[i][0]);
}
for(int i=0;i<p.size();i++)
{
for(int j=0;j<m;j++)
if(f[j][1].equals(p.get(i))) cnt++;
}
System.out.println(cnt);
}
}