package uniname;
import java.util.ArrayList;///for using array list
import java.util.Scanner;
public class Uniname
{
public static void main(String[] args) {
int n, U = 0, B = 0;
Scanner S = new Scanner(System.in);
ArrayList<String> ar = new ArrayList<String>(); ///create array list
System.out.println("Enter Total Student: ");
n = S.nextInt();
int size = n;
System.out.println("Name and Varsity: ");
S.nextLine(); ///this for Enter press
while (n > 0)
{
String Str = S.nextLine(); ///input string
ar.add(Str); ///send the string to arraylist
n--;
}
for (int i = 0; i < size; i++) {
String str1 = ar.get(i);
String[] A = str1.split(" "); ///split all words
///compare varsity name and count
///2nd string part is varsity name ***index 1
if (A[1].equals("BUET")) {
B++;
}
if (A[1].equals("UIU")) {
U++;
}
}
System.out.println("Total BUET: " + B + "
Total UIU: " + U);
}
}
Output
Enter total students:
2
Name& University:
Sabit UIU
Alom BUET
Total BUET: 1 Total UIU: 1
Add your comment