string

string

How to count a particular character in a given sentence and also displaying that contain word? Like I want to find "a" in the string "This is example of java Programme" and also display word that contain "a" character.

View Answers

September 10, 2012 at 5:12 PM

Here is a java example that accepts a sentence from the user and a character. It then count the occurrence of that character in the string and display the words that contains that character.

import java.util.*;

public class String_Example {
        public static void main(String[] args) {
            Scanner input=new Scanner(System.in);
            System.out.print("Enter any sentence: ");
            String st=input.nextLine();
            System.out.print("Enter character: ");
            char ch=input.next().charAt(0);
            int count=0;
                StringTokenizer tokenizer = new StringTokenizer(st);
                String s = "";
                System.out.println("Words that contains "+ch);
                while (tokenizer.hasMoreTokens()) {
                        s = tokenizer.nextToken();
                        if (s.contains(Character.toString(ch))){
                            count++;
                                System.out.println(s);
                        }
                }
                  System.out.println(ch+" occurs "+count+" times.");
        }
}

November 5, 2012 at 12:55 PM

thank you









Related Tutorials/Questions & Answers:
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
Advertisements
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... { public static String addSpaceToRight(String s, int n) { return String.format("%1$-" + n + "s", s); } public static String addSpaceToLeft(String s, int n
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  a java program to input a string and display the string...*; import java.io.*; public class FirstLetter{ public static String capitalizeFirstLetter( String str ) { final StringTokenizer st = new StringTokenizer( str
string
*; class 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
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
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
(ii) String and String Buffer Class
(ii) String and String Buffer Class  difference between String and String Buffer Class
(ii) String and String Buffer Class
String and String Buffer Class  differences between : String and String Buffer Class
(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
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
string program
string program  wap to find single occurrence of given string in java without using any predefined method
String progrm
String progrm  wap to count character of given string in java without using any method
String conversion
String conversion  I want to convert a string of mix cases(lower and upper case) to vice versa. ex. HellO should be printed to hELLo. the string comes from user using datainputstream. Also sending individual chars of string
Operations on string
Operations on string  Apply undo,redo operations on String pool in java
Java string
Java string  Strings are immutable.But String s="Hello"; String s1=s+"World"; S.O.P(s1); means printing "Hello World". How
string manipulation
string manipulation  Write a program in java and accept 10 strings form the user. store them in an array. then find the string with the maaximum length and print
reversing a string
reversing a string  how to reverse a string without using string function   class ReverseString { public static void main(String[] args) { String str="Hello World"; String st[]=str.split
copy string to string objective c
copy string to string objective c  How to copy a value of NSString to another string in Objective C? I have to different views and i am will to show the NSString value in both of them. Thanks
reverse string
reverse string  how to reverse a string without changing its place...{ public static void main(String[]args){ Scanner input=new Scanner(System.in); System.out.println("Enter string: "); String str
searching string
searching string   how to write a program for searching a string...{ public static void main(String[] args){ Scanner input=new Scanner(System.in); System.out.println("Enter string: "); String str = input.nextLine
intern() of String
intern() of String  Please explain me the working of intern().   Hello Friend, You can compare String objects and string characters... information, visit the following link: String intern() method Thanks
String question
String question  which method is used in java to eliminate the duplicate elements in String?   import java.util.*; class RemoveDuplicates{ public static void main(String[] args){ String[] str = new String[] { "Where
string related
string related  As with any other object, you can create String objects by using the new keyword and a constructor. The String class has thirteen constructors that allow you to provide the initial value of the string using
string wap
string wap  WAP to convert stack trace in to a String . Write that Stack Trace in Error Log File along with the class name and Method Name that has thrown the error.in java language
string increment
string increment  Sir, I want to auto icrement cust_id which is string whenevr i add customer, i cannot use integer Plz Help
Compare String with given String arraylists.
Compare String with given String arraylists.  I have one String for example abcThirtyFour. i have two arraylists of string. one contains one, two.... i was thinking of comparing given string with both the arraylists. but, i
string and substring
string and substring  bbbnnnmmm*ccc remove second asterick and display it as bbb*nnnADS_TO_REPLACE_1 mmm*ccc
string prgm
string prgm  write a java program which read a sentence and print occurence of each vowels in it seperatly
string program
string program  write a program to print the pattern p r o program r a m
array of string
java.util.Scanner; public class LastCheck { public static void main(String args[]){ int a; Scanner s= new Scanner(System.in); a=s.nextInt(); String ar[]=new String[a]; System.out.println(ar.length); for(int i=0;i<ar.length;++i
STRING FUNCTIONS
STRING FUNCTIONS  HERE IS THE QUESTION THAT I HAVE IN MY INFORMATICS... a string and 2 integers from user. It then changes the case of characters at those... StringExample{ public static String removeCharAt(String s, int pos
string to float
string to float  hiii. how can i change my string value in float for some operation?? give me some code for this??ADS_TO_REPLACE_1   hello, if rate is your textfield thenADS_TO_REPLACE_2 float FloPri
string manipulation
string manipulation  write a java program that asks the user to enter a string(where a consonant means insert, a punctuation means return element at the top and a vowel means remove the maximum) to be applied to an initially
string manipulation
string manipulation  write a java program that asks the user to enter a string(where a consonant means insert, a punctuation means return element at the top and a vowel means remove the maximum) to be applied to an initially
string and substring
string and substring  my code is bbbnnnmmm*ccc how to remove the asterick at second position and display the code as bbb*nnn mmm*ccc
string program
string program  reads sentence and find the average length of word... AverageLengthOfWords { public static void main(String[] args...); System.out.print("Enter sentence: "); String st=input.nextLine(); String str

Ads