write a java programming to create a string of size n by getting n value from the user. the n get the input and check whether input is junior senior if somstore in the array and vount the number of junior and senior if input othrr than junior senior then ouput shouldnbe invalid
Answers
Program in Java:
import java.util.*;
public class Main
{
public static void main(String[] args)
{
Scanner Sc = new Scanner(System.in);
int n, j = 0, s = 0;
String S;
System.out.print("Enter the number of elements in the array : ");
n = Sc.nextInt();
String A[] = new String[n];
for(int i = 0; i < n; i++)
{
System.out.print("Enter junior/senior : ");
S = Sc.next();
S = S.toLowerCase();
if(S.equals("junior") == true)
{
A[i] = "junior";
j++;
}
else if(S.equals("senior") == true)
{
A[i] = "senior";
s++;
}
else
{
System.out.println("Invalid Input");
i--;
}
}
System.out.println("Number of juniors : " + j);
System.out.println("Number of seniors : " + s);
}
}
Output:
Enter the number of elements in the array : 5
Enter junior/senior : junior
Enter junior/senior : senior
Enter junior/senior : None
Invalid Input
Enter junior/senior : JunioR
Enter junior/senior : Senior
Enter junior/senior : JUNIOR
Number of juniors : 3
Number of seniors : 2