In: Computer Science
Write a JAVA program that prompts the user to enter a single name. Use a for loop to determine if the name entered by the user contains at least 1 uppercase and 3 lowercase letters. If the name meets this policy, output that the name has been accepted. Otherwise, output that the name is invalid.
// TestCode.java
import java.util.Scanner;
public class TestCode {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
String s;
System.out.print("Enter name: ");
s = scan.nextLine();
int uppers = 0, lowers = 0;
for(int i = 0;i<s.length();i++){
if(s.charAt(i)>='A' && s.charAt(i)<='Z'){
uppers++;
}
if(s.charAt(i)>='a' && s.charAt(i)<='z'){
lowers++;
}
}
if(lowers>=3 && uppers>=1){
System.out.println("name has been accepted");
}
else{
System.out.println("name is invalid");
}
}
}

