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



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

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


Luke Coleman
frequency of a letter in a string
1 Answer(s)      3 years and a month 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  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
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
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
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
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  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
String  How to Convert sunnapu gopal to Sunnapu Gopal in java using String
String
String  write a program using string it should replace 'c'char to integer number as 1 in whole source
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
 

 

 

DMCA.com