Country Capital Java avg part 3
Country Capital
Input data containing N countries and their capital will be provided as input. The program must then print the capital for a given country.
import java.util.*;
public class Hello{
public static void main(String[] args)
{Scanner sc=new Scanner(System.in);
int n,flag=0;
n=sc.nextInt();
String[] country=new String[n];
String[] capital=new String[n];
for(int i=0;i<n;i++)
{
country[i]=sc.next();
capital[i]=sc.next();
}
String a=sc.next();
int i;
for(i=0;i<n;i++)
{
if(country[i].equals(a))
{
flag=1;
break;
}
}
if(flag==1)
{
System.out.print(capital[i]);
}
else
{
System.out.print("NONE");
}
}
}
Comments
Post a Comment