answersLogoWhite

0


Best Answer

The code is given at the bottom. This code requires JAVA 1.5+ version to be compiled.

This is very simple program. We ask user to input string and later we just iterate through all the character in the string. We use Character.isUpperCase() static method to check is the character we are checking is upper case if so we increase count variable by one. After iteration is done we print count variable and application quits.

Note: for statement was introduced in 1.5 JAVA version.

Example of usage:

david-mac:~ david$ java Test

Enter string: This is A Test String.

Your string has 4 upper case letters.

-------------------------

import java.io.*;

import java.lang.*;

public class Test

{

public static void main(String[] args)

throws IOException

{

BufferedReader in = new BufferedReader(new InputStreamReader(System.in));

System.out.print("Enter string: ");

String userString = in.readLine();

int count = 0;

for (char ch : userString.toCharArray())

{

if (Character.isUpperCase(ch))

{

count++;

}

}

System.out.println("Your string has " + count + " upper case letters.");

}

}

User Avatar

Wiki User

14y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: Write a java program to input a string and find the total number of uppercase letters in the string?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Related questions

Java program to convert lowercase to uppercase?

You can use the toUpperCase() method on a String to convert any String to all uppercase.


How do you uppercase letters in palindrome string?

Use toupper from ctype.h for every letter. Obviously, it doesn't matter if the string is palindrom or not.


Why is it a bad idea to name your class string?

If you are talking about Java, that will cause confusion with the built-in "String" class. Sure, Java will distinguish "String" (with an uppercase "S") from "string" (which has no uppercase letters), but it can be confusing for the programmer. In various other programming languages, the situation may be similar.


Write a program to generate uppercase using cSharp?

string s = "asdfqwer"; s = s.ToUpper(System.Globalization.CultureInfo.CurrentCulture);


What method returns the uppercase equivalent of a string?

The toUpperCase() method returns the uppercase equivalent of a string.


Write a program convert a string from uppercase to lower case and vice-versa without using string tolower and string toupper commands in TCL?

[ string toupper $str ] or [ string tolower $str ]


How do you identify the character in a string is uppercase?

In order to find whether a character in a string is in uppercase or not, you need to use the ascii\unicode values of the character. You may want to use the following code-- String str="Your Sample String Here"; //(say you have this string) int l=str.length(); for(int i=0;i<l;i++) { char ch=str.charAt(i); if(ch>=65&&ch<=90) //Since the values of block letters in ASCII are from 65 to 90 System.out.println(ch); } //This program basically prints out the block letters, but you can modify it as you like, by changing the statement after 'if' as you want


What is the use of Reverse String in C program?

The use of the reverse string in C program is used to reverse the letters in the string. An example would be reverse me would be reversed to em esrever.


Changing a word to all uppercase letters in c plus plus?

To change any string to uppercase, loop through each character in the string. If the character is in the range 'a' through 'z', decrement the character by decimal 32 (the difference between ASCII value 'a' and 'A'). The following function shows an example of this: void to_upper(std::string& str) { for(int i=0; i<str.size(); ++i) if(str[i]>='a' && str[i]<='z') str[i]-=32; }


How to write A Java program to print number of digits in a given number?

One way to do this is to convert the number to a String, then use the corresponding String method to find out the length of the String.


What does the PROPER function do in Excel?

The proper function in Excel causes the first letter in a text string and any other letters in text that follow any character other than a letter to be changed into uppercase. It converts all other letters to lowercase letters.


How to Uppercase the all vowels in Java?

Assuming that you want to uppercase only the vowels in a String, you can write a loop to go through all the chracters in a String and when a character is a vowel you can convert it to uppercase. I think one way to do this is as follows:String originalString = "aobxkijejku";StringBuffer buffer = newStringBuffer(originalString);for(int i = 0, len = originalString.length(); i < len; i++){if(buffer.charAt(i) 'u'){buffer.setCharAt(i, 'U');}}String modifiedString = buffer.toString();