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



Home Answers Viewqa Java-Beginners frequency of a letter in a string

Have Programming Question? Ask it here!
 
 
 


Luke Coleman
frequency of a letter in a string
1 Answer(s)      2 years and 6 months ago
Posted in : Java Beginners


Could someone answer in netbeans please

Write a program that takes in a string and a letter from the user and displays the number of appearances of the entered letter in the entered string.


Advertisement
View Answers

February 22, 2012 at 10:06 AM


import java.io.*;
import java.util.*;

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


Related Tutorials/Questions & Answers:
frequency of a letter in a string
frequency of a letter in a string  Could someone answer in netbeans please Write a program that takes in a string and a letter from the user and displays the number of appearances of the entered letter in the entered string
Java count frequency of words in the string
Java count frequency of words in the string. In this tutorial, you will learn how to count the occurrence of each word in the given string. String..., input validation, and file conversion. Here we are going to find the frequency
Advertisements
Count letters in a string.
Description: This tutorial demonstrate how to find number of letter exists in a string. The str.length() method find the length of string. Code...;public static void main(String[] args) {   
how to delete a letter in a word?
how to delete a letter in a word?  how to delete a letter in a word? for example if i enter= roseindia, i want to delete 's', then output= roeindia
letter counting for the smallest word
letter counting for the smallest word  How do I program my java... static void count(final String str){ Runnable readRun1 = new Runnable...); String st=str.replaceAll(" ", ""); char ch[]=st.toCharArray
Automatic Capital letter
to make a automatic capital letter. I have a jTextfield1, if i type aaaaaa...); label=new JLabel("Enter String:"); p=new JPanel(); p.add(label); p.add(text...(KeyEvent e){ String st=text.getText(); text.setText
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... it here is my coding: public int countCharset(String s, String cc) { return
POI Word document (Letter Template)
POI Word document (Letter Template)  Dear Team, i need code for generating word document(letter format). i am unable to get the code for formats, font settings, letter type settings. please help me for the same. Thanks
Check for character is letter or not.
Description: This tutorial demonstrate the use of Character.isLetter() method which checks whether the value stored in char data-type variable is letter...;{   public static void main(String[] args) 
Check for character is letter or digit.
is a digit or letter using isLetterOrDigit() method. Code...;static void main(String[] args) {     
Welcome! to the News letter archive
News Letter Archive     ... letter sent our users.   Newsletters are regularly distributed...; News Letter Archive Date Subject
How to delete line starting with a letter in java Regex?
How to delete line starting with a letter in java Regex?  Hi, i 'm... lines which starts with a letter like G or g in a text. i tried this but it's not working, please i need help. [CODE] String[] paras = Pattern.compile("(?i)((s
string
inputString = br.readLine(); FirstLetter letter=new FirstLetter(); String words...string  a java program to input a string and display the string...*; import java.io.*; public class FirstLetter{ public static String
Display first letter of every word in uppercase
Display first letter of every word in upper case In this Java tutorial section, you will learn how to display the first letter of every word in uppercase. For this, we have allowed the user to enter the string. The BufferedReader class
display a list of names(when we press first letter)
("Enter letter: "); String letter=input.next().substring(0,1...: "); String letter=input.next().substring(0,1); System.out.println...display a list of names(when we press first letter)  If i gave
Display set of names in array when we press the first letter
("Enter letter: "); String letter=input.next().substring(0,1... click the starting letter (like in gmail if we press the letter it will show... java.util.*; class DisplaySetOfNames{ public static void main(String[] args
program to display frequency count of each word in a file using Hashmap, Hashset and streamtokenizer.plz help me out ..
program to display frequency count of each word in a file using Hashmap... java.util.*; class test1 { public static void main( String args[])throws IOException { Console con= System.console(); String fname; System.out.println
STRING.....
STRING.....  plzz sent me d code for counting vowels in a string... gui programme
string
string   difference detween "public static void main (String[] args) " and "public static void main (String args[])" in java but it executes both... "String args[]" can mean a "string array called args which is an array
string
string  String helloString = new String(helloArray); System.out.println(helloString); i am unable to understand this. could u plz explain
String
String  how to add spaces with string functions.?   Hi... String addSpaceToRight(String s, int n) { return String.format("%1$-" + n + "s", s); } public static String addSpaceToLeft(String s, int n) { return
string
string  a java program using string function to input any string... ArrangeStringAlphabetically { public static void main(String[] args) { Scanner input=new Scanner(System.in); System.out.print("Enter string
String
characters in string?   import java.util.*; class RemoveDuplicateCharatcersFromString { public static String removeDuplicates(String s... < s.length(); i++) { String st = s.substring(i, i + 1
String
String  write down the code of remove any character from a given string without using any string function   please give me the code of remove any given character from a given string without using function
string
ExtractWords { public static void main(String[] args) { Scanner input=new Scanner(System.in); System.out.print("Enter String: "); String st=input.nextLine(); String str[]=st.split(" "); for(int i=0
string
string   just i want to a program in a short form to the given string in buffered reader for example input string: Suresh Chandra Gupta output: S. C...; public class StringTest { public static void main(String [] args
string
string  write a program to accept the string and store the reverse stream into another array and print
string
string  java prgm to find total occurence of a given string pattern in a sentence
string
string  java prgm to find total occurence of a given string pattern in a sentence
String
String  write a program using string it should replace 'c'char to integer number as 1 in whole source
String
String  How to Convert sunnapu gopal to Sunnapu Gopal in java using String
String
String  how to print in between numbers if the question "String s = "1,2,3,4,5,6,8,-25"" out must be 1 2,3,4,5,6,7,8,9,10,upto25
string
and also displaying that contain word? Like I want to find "a" in the string... and a character. It then count the occurrence of that character in the string and display... String_Example { public static void main(String[] args
string
string  program for String reverse and replace in c,c++,java e.g.Input:10,20,hello output:hello;20;10   Hi Friend, Try the following java...(String[] args) { String array[]=new String[5]; Scanner input
string
string  a java program using string function that computes your initials from your full name and display them   Please visit the following links: http://www.roseindia.net/tutorial/java/core/printInitials.html http
string
string  a java program using string function and access modifiers to automate the insurance company which will have to manage the information about policy holders Data Members: 1)Policy No 2)Name of policy holder 3)Address 4
display all words containing the letter which i gave as input...
display all words containing the letter which i gave as input...  If i enter any character,it have to display the names which having that character..write a program using java example(output) Enter any character: a Names: Abi
java programmming: string manipulation
the command prompt and find the frequency of the character e in the input string...java programmming: string manipulation  WAP to accept a string from the user, using buffered reader and then find the frequency of character 'e
string object
string object  Hi, how do i write a program that works with a user's password, when the program should prompt the user for a possible password, that is between 6 and 10 characters long, that contains at least one letter
String Function Program
String Function Program  The string function program is just an application of the string manipulation functions in JAVA. The program is designed to count the number of one-letter word, two-letter word, and three-letter words
read string - using loops in Java
read string - using loops in Java  Write a program to read a string composed of an unknown number of words, then count the number of words in the string, and Display the longest and shortest words, with first letter Uppercase
Arrays, loops and string handling
capital or small letters. Extract each letter from this string and fill...Arrays, loops and string handling  How would i go about in creating... correct answers using JOptionPane dialog box and store the entire answer as on string
(ii) String and String Buffer Class
String and String Buffer Class  differences between : String and String Buffer Class
(ii) String and String Buffer Class
(ii) String and String Buffer Class  difference between String and String Buffer Class
String Ques
String Ques  what is difference between String str="abc"; and String str=new String("abc");   Hello Friend, Differences: 1)String str=new string("abc") creates two objects, one in heap memory and one in string
(ii) String and String Buffer Class
String and String Buffer Class  difference between String and String... between String and StringBuffer 1) String object is immutable whereas StringBuffer objects are mutable. 2) String objects are constants
 

 

 

DMCA.com