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");
    }
}









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
Count Characters from the input string Java
Count Characters from the input string of Java In this section, you will learn how to count the occurrence of each character in the string. For this, we have... to count the occurrence of each character of the array.  Here is the code
Count characters from text file in Java
Count characters from text file Using Java Here we are going to count... it into character array in order to count the occurrence of each character...; char ch= third[counter];   int count=0;  
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... Java Word Count - Word Count Example in Java  
Java characters
Java characters  How many bits are used to represent Unicode, ASCII, UTF-16, and UTF-8 characters
writing characters
writing characters  how to write a group of characters to a string ... i mean for writing single character using charAt in java
Unwanted characters instead of arabic characters
Unwanted characters instead of arabic characters  I am using... and using it to display. the problem is: I need to display some arabic characters here... صÙ?Ù?دÙ?Ù?Ø© سÙ?Ù?د Ù?Ù?Ù?Ù?Ù?أرب like characters instead of arabic
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
special characters in my HTML
special characters in my HTML  How do I get special characters in my HTML
special characters in my HTML
special characters in my HTML  How do I get special characters in my HTML
Protect Special Characters.
Protect Special Characters.  How To Protect Special Characters in Query String
characters java - Java Beginners
.(REmember that the alphabet contains 52 characters if you count uppercase... " +str + " has " +j +" characters"); System.out.println(""); } int count(char...characters java  HELLO MAM AND SIR I ASK YOUR HELP HOPE YOU GONNA
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
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
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
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
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
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
count objects php
count objects php  How to Count and show objects in PHP
Count Rows - JSP-Servlet
Count Rows  How to count rows in Java. Thanks
letter count problem - Java Beginners
letter count problem  i have a problem in my java coding to count two characters of a string. eg to count the letter "ou" in the string "How do you feel today?". The answer should be 5. but i still have error compiling
Limiting characters - JSP-Servlet
Limiting characters  Iam doing a jsp project. In this i have a text area which should accept not more than 300 characters. I solved this with backspace and delete keys. But, i cannot solve problem of pasting through shortcut ctrl
Remove unknown characters php - PHP
Remove unknown characters php  i am looking for a script that can remove unknown characters in PHP code except white spaces
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
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
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
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
php array loop count
php array loop count  Count the array using loop in php
Iterating the Characters of a String
Iterating the Characters of a String This section illustrates you how to iterate the characters of a string. For bi-directional iteration over the text , you... this interface for the string. In CharacterIterator, characters are indexed
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.ADS
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
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 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
Hibernate Count
In this section you will learn different way to count number of records in a table
How To Protect Special Characters in Query String?
How To Protect Special Characters in Query String?  How To Protect Special Characters in Query String
count in java - Java Beginners
count in java  Hello javamania.... i want to ask something like... is 20. i have JFrame Form(jTextField,jLabel,jButton), i want to get count of gender, like if jTextfield =male then count of male=50 and if jTextfield=female
How to avoid the Special characters? - JDBC
How to avoid the Special characters?  I have a form in jsp... can I override special characters by submitting a form through JAVA...,   hi friend, To avoid special characters we have imposed some
Count Row - JSP-Servlet
Count Row  Hello all, Please I need your help on how to desplay... db = "register"; String driver = "com.mysql.jdbc.Driver"; int count= 0...(); ResultSet res = st.executeQuery("SELECT COUNT(*) FROM regiform
write Greek ( or other non-ASCII/8859-1 ) characters to a database
write Greek ( or other non-ASCII/8859-1 ) characters to a database  How do I write Greek ( or other non-ASCII/8859-1 ) characters to a database

Ads