Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


remi
index
1 Answer(s)      5 years and 2 months ago
Posted in : Java Beginners



Advertisement
View Answers

August 10, 2009 at 4:40 PM


Hi Friend,

Try the following code:

import java.io.*;
import java.awt.*;
import java.util.*;
import javax.swing.*;

class CountCharacters {
public static void main(String[] args) throws Exception{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
System.out.print("Please enter string ");
System.out.println();
String str=br.readLine();
String st=str.replaceAll(" ", "");

char[]third =st.toCharArray();
for(int counter =0;counter<third.length;counter++){
char ch= third[counter];
int count=0;
for ( int i=0; i<third.length; i++){
if (ch==third[i])
count++;
}
boolean flag=false;
for(int j=counter-1;j>=0;j--){
if(ch==third[j])
flag=true;
}
if(!flag){
System.out.println("Character :"+ch+" occurs "+count+" times ");
}
}
}
}

Hope that it will be helpful for you.
Thanks


Related Tutorials/Questions & Answers:
What is Index?
What is Index?  What is Index
Advertisements
index of javaprogram
index of javaprogram  what is the step of learning java. i am not asking syllabus am i am asking the step of program to teach a pesonal student.   To learn java, please visit the following link: Java Tutorial
Drop Index
Drop Index       Drop Index is used to remove one or more indexes from the current database. Understand with Example The Tutorial illustrate an example from Drop Index
clustered and a non-clustered index?
clustered and a non-clustered index?  What is the difference between clustered and a non-clustered index
Mysql Btree Index
Mysql Btree Index  Mysql BTree Index Which tree is implemented to btree index? (Binary tree or Bplus tree or Bminus tree
z-index always on top
z-index always on top  Hi, How to make my div always on top using the z-index property? Thanks   Hi, You can use the following code: .mydiv { z-index:9999; } Thanks
array, index, string
array, index, string  how can i make dictionary using array...please help
$_GET[] index is not defined
$_GET[] index is not defined  Hi, What could be solution of the error: $_GET['someparameter'] index is not defined Thanks   Hi, You can use the following code: if (isset($_GET['someparameter'])) { // your code
NSMutableArray change object at Index
NSMutableArray change object at Index   NSMutableArray change object at Index   // Browse all messages (you can use "for (NSDictionary *message in allMessageArray)" enumerate loop but because we need the index
checking index in prepared statement
checking index in prepared statement  If we write as follows: String query = "insert into st_details values(?,?,?)"; PreparedStatement ps = con.prepareStatement(query); then after query has been prepared, can we check the index
JavaScript array index of
JavaScript array index of  In this Tutorial we want to describe that makes you to easy to understand JavaScript array index of. We are using JavaScript... line. 1)index of( )  - This return the position of the value that is hold
Drop Index
Drop Index       Drop Index is used to remove one or more indexes from the current database... Index. In this example, we create a table Stu_Table. The create table is used
alter table create index mysql
alter table create index mysql  Hi, What is the query for altering table and adding index on a table field? Thanks
alter table create index mysql
alter table create index mysql  Hi, What is the query for altering table and adding index on a table field? Thanks   Hi, Query is: ALTER TABLE account ADD INDEX (accounttype); Thanks
Java arraylist index() Function
Java arrayList has index for each added element. This index starts from 0. arrayList values can be retrieved by the get(index) method. Example of Java Arraylist Index() Function import
creating index for xml files - XML
creating index for xml files  I would like to create an index file... after another and then retrieve each tag and create index to that file. In some cases, more than one file may have same name. So, my index file would be like
Mysql Date Index
Mysql Date Index       Mysql Date Index is used to create a index on specified table. Indexes... combination of columns in a database table. An Index is a database structure which
including index in java regular expression
including index in java regular expression  Hi, I am using java regular expression to merge using underscore consecutive capatalized words e.g., "New York" (after merging "New_York") or words that has accented characters
How to index a given paragraph in alphabetical order
How to index a given paragraph in alphabetical order  Write a java program to index a given paragraph. Paragraph should be obtained during runtime... paragraph : This is a technical round. Please index the given paragraph. Output
Write a query to display a row using index
Write a query to display a row using index  Write a query to display a row using index
Foreach loop with negative index in velocity
Foreach loop with negative index in velocity  ... with negative index in velocity. The method used in this example... have used foreach loop with negative index..  
Index Out of Bound Exception
Index Out of Bound Exception       Index Out of Bound Exception  are the Unchecked Exception... the compilation of a program. Index Out of Bound Exception Occurs  when
Pointing last index of the Matcher
Pointing last index of the Matcher   ... and also indicate the last index of the matcher using expression.For this we... will arrive.":- Declaring text as String in which last index of word Tim
JavaScript array index of
JavaScript array index of   ... to easy to understand JavaScript array index of. We are using JavaScript...)index of( )  - This return the position of the value that is hold
Spring Constructor arg index
Constructor Arguments Index In this example you will see how inject the arguments into your bean according to the constructor argument index...;    <constructor-arg index="0" value
Writes the given double value into a buffer at the given index.
Writes the given double value into a buffer at the given index. In this tutorial you will see how to write the given double into buffer at the given index. The put (int index, double d) allow to write a character at particular index
Writes the given character into buffer at the given index.
Writes the given character into buffer at the given index. In this tutorial you will see how to write the given character into buffer at the given index. The put (int index, char c) allow to write a character at particular index
Write a byte into byte buffer at given index.
Write a byte into byte buffer at given index.  In this tutorial, we...; index. ByteBuffer API: The java.nio.ByteBuffer class extends... ByteBuffer putChar(int index, byte b) The putChar(..) method write
PHP PDO Index
sqlite2   This is the index page of PDO, following pages will illustrate
Advertisements
 

 

 

DMCA.com