# Count Capital Letters in Java

Oct 17, 2021

Machine Problem

Write a Java program to ask the user a string and then the program will count the number  of capital letters in the given string by user.

I am currently accepting programming work, IT projects, school and application development, programming projects, thesis and capstone projects, IT consulting work, computer tutorials, and web development work kindly contact me at the following email address for further details.  If you want to advertise on my website kindly contact me also in my email address also. Thank you.

My mobile number here in the Philippines is 09173084360.

Program Listing

``````/*
*  Capital_Letters.java
*
*  Jake Rodriguez Pomperada, MAED-IT, MIT
*  Bacolod City, Negros Occidental Philippines
*
* Machine Problem
*
* Write a Java program to ask the user a string and then the program will count the number
* of capital letters in the given string by user.
*/

import java.util.Scanner;

public class Capital_Letters {

private static long countUpperCase(String s) {
return s.codePoints().filter(c-> c>='A' && c<='Z').count();
}

public static void main(String[] args) {

Scanner input = new Scanner(System.in);

System.out.println();
System.out.println("\tCount Capital Letters in Java");
System.out.println();

System.out.print("\tEnter a String : ");
String val_str = input.nextLine();

long count_Capital = countUpperCase(val_str);

System.out.println();
System.out.print("\tNumber of Capital Letters : " + count_Capital);
System.out.println("\n\n");
System.out.println("\tEnd of Program");
System.out.println();
}

}``````