Hi,
This is ravi i have a question like this i have string
"UNDERSTAND" now i want to count the letters how many times
it occures.i.e from the above string the out put should be
like this U-1,N-2,D-2,E-1,R-1,S-1,T-1,A-1.
how can i achieve this
Thnaks in advance for your response ..
Answer Posted / pradeep mishra
public class CountOccur {
String str="ANAND";
int c1=0;
int c2=0;
int c3=0;
String retun=null;
public static void main(String[] args) {
CountOccur co=new CountOccur();
System.out.println("Ocurrence "+co.Test());
}
public String Test() {
for( int i=0;i<str.length();i++){
if(str.charAt(i)=='A')
c1++;
if(str.charAt(i)=='N')
c2++;
if(str.charAt(i)=='D')
c3++;
}
retun="A"+c1+"N"+c2+"D"+c3;
return retun;
}
}
| Is This Answer Correct ? | 1 Yes | 0 No |
Post New Answer View All Answers
What is the purpose of the System class?
What happens to the Exception object after handling an exception?
I am a fresher and know core java, c languge, html, css etc if I am illegible for any job then send it on my email tatranakshay276@gmail.com
How to sort double array in java?
Explain the difference between static and dynamic binding in java?
What is generic type?
What are the types of collections in java?
Why does java not support pointers?
What is java string pool?
What is java util list?
For ease of programming you can consider the maze as a 2D array with colors represented by below integer and characters (in capital letters). • B - Black • W -White • G- Green • R- Red R B W B W W W W W W B W B B W W W W W W W B W B W W W B W W W W B B W W W B W W W B W W B B B B W B W B W W B W W W B W W W B B B W W B W W W B W W B W B W W W B W B W W W W B B W W W W B W W W W W G Shortest Route Problem: • Solution that finds the shortest Route between Red and Green White will have 1 Weight. Red and Green carry no weights. Shortest path is the path with less weight when you add up the weights in the path.
What is variable explain?
What is the collections api?
How can we make a class virtual?
Can a abstract class be declared final?