count characters

count characters

i have to print the total number of char 'A' in all string entered..

example: please enter your string: selangor melaka kedah sabah sarawak terengganu

the output must be count the total number of char 'A'...

View Answers

March 1, 2012 at 10:30 AM

import java.util.*;

class CountCharacter
{
    public static void main(String[] args) 
    {
        int count=0;
        Scanner input=new Scanner(System.in);
        System.out.print("Enter string: ");
        String str=input.nextLine();

        char arr[]=str.toLowerCase().toCharArray();
        for(int i=0;i<arr.length;i++){
            if(arr[i]=='A'||arr[i]=='a'){
                count++;
            }
        }
        System.out.println("Character occurs "+count+" times");
    }
}

March 1, 2012 at 10:30 AM

import java.util.*;

class CountCharacter
{
    public static void main(String[] args) 
    {
        int count=0;
        Scanner input=new Scanner(System.in);
        System.out.print("Enter string: ");
        String str=input.nextLine();

        char arr[]=str.toLowerCase().toCharArray();
        for(int i=0;i<arr.length;i++){
            if(arr[i]=='A'){
                count++;
            }
        }
        System.out.println("Character occurs "+count+" times");
    }
}

Ads









Related Tutorials/Questions & Answers:
count characters
count characters  i have to print the total number of char 'A' in all... sabah sarawak terengganu the output must be count the total number of char... main(String[] args) { int count=0; Scanner input=new Scanner
Count number of characters in a column.
Count number of characters in a column.  I just need you suggestions. Am from Biology Back ground. I just need to find out number of characters... to count characters in 1st, 2nd, 3rd columns seperatly and also print flase if i
Advertisements
Count characters from text file in Java
Count characters from text file in Java  At the "Count chracters fro... is a java code that count the occurrence of each character from text file. import...++){ char ch= third[counter]; int count=0; for ( int i=0; i<third.length; i
Java count characters from file
Java count characters from file In this section, you will learn how to count characters from the file. Description of code: Firstly, we have used FileReader... into character array in order to count the occurrence of each character
Java Word Count - Word Count Example in Java
to count the number of lines, number of words and number of characters... some strings and program will count the number of characters and number of words... of characters, number of lines. To count the number of words call
writing characters
writing characters  how to write a group of characters to a string ... i mean for writing single character using charAt in java
count in hibernate .
count in hibernate .  How to implements count in hibernate
Count the character in java
.   Count characters by implementing thread import java.util.*; class...[]=st.toCharArray(); int count=ch.length; System.out.println("Total Characters...Count the character in java  Write a java program to count
Character count by while loop
Count Characters...Character count by while loop  Write the program to count the number of characters entered until a full stop (.)is keyed-in. Anyone there pls help
Protect Special Characters.
Protect Special Characters.  How To Protect Special Characters in Query String
ModuleNotFoundError: No module named 'characters'
ModuleNotFoundError: No module named 'characters'  Hi, My Python... 'characters' How to remove the ModuleNotFoundError: No module named 'characters' error? Thanks   Hi, In your python environment you
remove special characters iphone
remove special characters iphone  remove special characters iphone   Remove special characters iphone from Password NSString *outputString = [passwordString stringByReplacingOccurrencesOfString:@"%" withString
PDF Generation for unicode characters
PDF Generation for unicode characters  Hi, How a PDF file having unicode characters is generated in JSP
regular expression for special characters
regular expression for special characters  How to find out regular expression for special characters
count the users?
count the users?  how to get the number of users logged in any application
Count number of "*"
Count number of "*"  I have this code to count the number of * from...:"); String text = bf.readLine(); int count = 0; for (int i = 0; i...); if (c=='*' ) { count
replace special characters in html
replace special characters in html  How can i replace the special characters in HTML?   Special Character in HTML HTML has a long list of special characters symbol that can be used anywhere throughout the HTML Code
Count Vowels
Count Vowels   Read a string from the user, your program counts the number of vowels in the text and have it report a sum of each vowel found as well as the number of spaces. Make it in two classes
Removing characters from a string
Removing characters from a string  Removing characters from a string   Example: public class CharReplace{ public static void main(String []args){ String str="Hello 123.you are At 3456"; String
Uppercase Characters in Java
Uppercase Characters in Java  I want to know how to UpperCase Characters in Title useing a java code...?   Use toUpperCase() method to convert the string in uppercase letters. class UppercaseString { public static
ModuleNotFoundError: No module named 'control-characters'
ModuleNotFoundError: No module named 'control-characters'  Hi, My... named 'control-characters' How to remove the ModuleNotFoundError: No module named 'control-characters' error? Thanks   Hi, In your
ModuleNotFoundError: No module named 'control-characters'
ModuleNotFoundError: No module named 'control-characters'  Hi, My... named 'control-characters' How to remove the ModuleNotFoundError: No module named 'control-characters' error? Thanks   Hi, In your
SQLl query count and group by
SQLl query count and group by  How to write a sql query to count and group by the data?   Sql query to count the data and group the data using group by function... Select Name, Count(Name) As Count From Table Group
ModuleNotFoundError: No module named 'the_count'
ModuleNotFoundError: No module named 'the_count'  Hi, My Python... 'the_count' How to remove the ModuleNotFoundError: No module named 'the_count' error? Thanks   Hi, In your python environment you
Hibernate Criteria Count Example
Hibernate Criteria Count Example  Example of Hibernate Criteria Count. Check the tutorial Hibernate Criteria Count. Check the Latest tutorials, articles and examples of Hibernate Framework. Thanks
Stripping of unwanted characters from string
Stripping of unwanted characters from string  how to strip off unwanted characters from a string   Hi Friend, Try this: public class StripCharacters { public String strip(String s) { String st
MySQL Count
MySQL Count       This example illustrates how to use count() in MySQL database. Count(): The Count.... It returns a numeric value. If you use COUNT(*) that counts the number of rows.  
retain count in Objective C
retain count in Objective C  what is the retain count in Objective C?   retainCount in Objective c retainCount: retain count method is used to show the internal count of the given object so that programmer can easily
Count distinct value in HQL.
Count distinct value in HQL.  How do you count distinct value in HQL?   count(distinct fieldName) returns number of distinct value... = sessionFactory.openSession(); String countHql = "Select count(distinct salary
Hibernate Count
In this section you will learn different way to count number of records in a table
Hibernate criteria count.
Hibernate criteria count.  How do we count rows using criteria in hibernate?   We can get the rows count using the Projections. My code is like this: Criteria criteria = session.createCriteria(getReferenceClass

Ads