Home Answers Viewqa Java-Beginners Count number of "*"

 
 


Sincole Brans
Count number of "*"
2 Answer(s)      7 months ago
Posted in : Java Beginners

I have this code to count the number of * from a string entered. but I need to find it from an text file. Any idea?

import java.lang.String;

import java.io.*;

import java.util.*;


public class CountVowels

{

    public static void main(String args[])throws IOException

    {

        BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));

        System.out.println("Enter the String:");

        String text = bf.readLine();

        int count = 0;

        for (int i = 0; i < text.length(); i++) {

            char c = text.charAt(i);

            if (c=='*' ) {

                count++;

            }

        }

        System.out.println("The number of vowels in the given sentence are " + count);

    }

}
View Answers

October 10, 2012 at 4:14 PM


The given code counts the number of vowels present in the text file data.

import java.io.*;

public class CountVowels {
public static void main(String[] args)throws Exception{

try{
    FileInputStream fstream = new FileInputStream("c:/data.txt");
    DataInputStream in = new DataInputStream(fstream);
    BufferedReader br = new BufferedReader(new InputStreamReader(in));
    int count=0;
     String str="",st="";
     char ch;        
     while((str=br.readLine())!=null){
         st+=str;
     }
     for (int i=0;i<st.length();i++){
      ch = st.charAt(i); 
      if(( ch == 'a') ||( ch == 'e') ||( ch == 'i') ||( ch == 'o') ||( ch == 'u')){
        count++;
      }
     }
     System.out.println("Number of vowels in the file: "+count);
      br.close(); 
    }
     catch (Exception e) {
     System.err.println(e);
    }
   }
 }

October 10, 2012 at 9:09 PM


Thanks.. worked great









Related Pages:
Count number of "*"
Count number of "*"  I have this code to count the number of * from...:"); String text = bf.readLine(); int count = 0; for (int i = 0; i...); if (c=='*' ) { count
Count number of characters in a column.
Count number of characters in a column.  I just need you suggestions. Am from Biology Back ground. I just need to find out number of characters... to count characters in 1st, 2nd, 3rd columns seperatly and also print flase if i
Count number of nodes
(struct node *p ) { int count=0; while (p != NULL) { count ++; p = p->link; } return(count); } void main() { int n; int x; struct node *start = NULL ; printf("Enter number of nodes to be created
count the users?
count the users?  how to get the number of users logged in any application
Count Vowels
Count Vowels   Read a string from the user, your program counts the number of vowels in the text and have it report a sum of each vowel found as well as the number of spaces. Make it in two classes
Count number of occurences and print names alphabetically in Java
Count number of occurences and print names alphabetically in Java  I... for the printCount() method for the code to count the number of occurences of each...]+" "; } str = str.toLowerCase(); int count = -1
count characters
count characters  i have to print the total number of char 'A' in all... sabah sarawak terengganu the output must be count the total number of char... main(String[] args) { int count=0; Scanner input=new Scanner
Hibernate Count
In this section you will learn different way to count number of records in a table
How can we know the count/number of elements of an array?
How can we know the count/number of elements of an array?  How can we know the count/number of elements of an array
java program to insert data into a file and count the number of words from the file???????
java program to insert data into a file and count the number of words from the file???????  java program to insert data into a file and count the number of words from the file
Count numbers of spaces and number of words from the input string
Count numbers of spaces and number of words from the input string Java In this section, you will learn how to count the number of spaces and words from... the number of spaces. Now, in order to count the number of words, we have splitted
Java count occurrence of number from array
Java count occurrence of number from array Here we have created an example that will count the occurrence of numbers and find the number which has... and accepted the numbers through the console. We have restricted to enter the number above
PHP Array Count Values
PHP Array Count Values  Sometimes  we need to count the number... array_count_values() function to count the number of variables.  General...); echo"Counting the number of values are:"; print_r(array_count_values
Java: Example - Count occurences
Java: Example - Count occurences Problem: Count the number of times one string is found in another. //-------------------------------------------- count() int count(String base, String searchFor) { int len
Program to count the number of unique words in a file using HashMap
Program to count the number of unique words in a file using HashMap  import java.io.File; import java.io.FileNotFoundException; import java.util....()); System.out.println("The number of unique words: "+uniqueValues.size
Count distinct value in HQL.
Count distinct value in HQL.  How do you count distinct value in HQL?   count(distinct fieldName) returns number of distinct value... = sessionFactory.openSession(); String countHql = "Select count(distinct salary
Java Word Count - Word Count Example in Java
to count the number of lines, number of words and number of characters... some strings and program will count the number of characters and number of words... 'numWords' is used to count the number of words. linecount(String fileName
MySQL Count
. It returns a numeric value. If you use COUNT(*) that counts the number of rows.  ... MySQL Count       This example illustrates how to use count() in MySQL database. Count(): The Count
Character count by while loop
Character count by while loop  Write the program to count the number...]; 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
PHP array count
The PHP array_count_values() function is used to count the elements in the array. It returns the number of counting with values in associative array form. In returned array, key is the array's values and values are the number
Java file line count
Java file line count In the section, you will learn how to count the number...("Number of Line: " + count); } } In this section, we have used data.txt file... till the end of the file. We have used counter here to detect the number
Count words in a string method?
count the length of arr which return the number of words in the inputted string...Count words in a string method?  How do you Count words in a string...=br.readLine(); int count=0; String arr[]=st.split
Count Row - JSP-Servlet
("Number of column:" +count); } catch (SQLException ex...Count Row  Hello all, Please I need your help on how to desplay the number of row(s) affected along with the affected row(s) in mssql database 2000
count asterisk in a grid - Java Beginners
count asterisk in a grid  I need to write a program that uses a recursive method to count the number of asterisk in a square grid
J2ME count character into string
J2ME count character into string  i am new in J2ME, my problem is how to count character into number, i had been research google for almost 2 days and got nothing...some one plz give me a punch :) as an example, 1. i got a text
Count instances of each word
Count instances of each word  I am working on a Java Project... of the words preceded by the occurrence count. My program compiles and runs... number 1 of 1 program 2 test 2 that 1 the 1 this 1 to 1 total 1 using 1 verify 1
NSArray Count Example
NSArray Count Example In the example, we are going to count the number of elements in an array in objective c programming. In Objective C language, Count is a primitive instance method that returns the number of objects available
PHP Array Count
PHP Array Count Function To count the elements of an array PHP provides count.... The count() and sizeof() functions are identical. There is no such difference between these two functions.  General Format int count( mixed
Hibernate criteria count.
Hibernate criteria count.  How do we count rows using criteria in hibernate?   Create hibernate configuration file (hibernate.cfg.xml... list = criteria.list(); System.out.println("Number of employee : "+list.get
JDBC: Rows Count Example
JDBC: Rows Count Example In this section, You will learn how to count number of rows in a table using JDBC API. Counting number of rows - To count the number of rows of a table we use COUNT(*). It will returns the number of rows
Java file number of lines
Java file number of lines In this section, you will learn how to count the number of lines from the given file. Description of code: Java has provide... have used counter here to detect the number of lines occurred in the file
Primary number
Primary number  write a program to find the 100th or nth primary number?   import java.util.*; class PrimeNumber{ public static void...) { count++; } } if(count==n
Primary number
Primary number  write a program to find the 100th or nth primary number?   import java.util.*; class PrimeNumber{ public static void...) { count++; } } if(count==n
Hibernate Criteria Count
Hibernate Criteria Count The Hibernate Criteria Count is used to count the numbers of records in a table. To Count a number of records in a table make... count(*) as y0_ from student this_ No Of Record in table is - 6
Column count doesn't match value count at row 1
Column count doesn't match value count at row 1  Column count doesn't match value count at row 1 UPDATE user_profile SET id=[value-1],user_id...],website=[value-12],alternate_contact_number=[value-13],occupation=[value-14
how to find [count the number of integers whose value is less than the average value of the integers]
how to find [count the number of integers whose value is less than the average... amount to the screen integers from an operator at a terminal, and count the number... program is to display the average integer value and the count of integers less
column count using metadata
GET COLUMN COUNT USING "RESULTSETMETADATA"   In this program ,we will get column count using "resultsetmetadata ".Using resultset... = rs.getMetaData();     int NumOfCol=rsmd.getColumnCount();     System.out.println("Number
Java Count Vowels
Java Count Vowels       In this program you will learn how to count vowels in a String. Here you... the number of vowels from that String. Description of the code: In the program code
Java count files in a directory
directory. But we have to count the number of files so we have initialized...++; } } System.out.println("Number of files: " + count); } } Through the above code, you can count the number of files available in the directory. Output
Retrieve a list of words from a website and show a word count plus a specified number of most frequently occurring words
; Integer count; // number of occurrences WordPair(String word...Retrieve a list of words from a website and show a word count plus a specified number of most frequently occurring words  I have to: 1.Retrieve
JDBC Select Count example
; returns a count of the number of rows retrieved, whether or not they contain...; change the COUNT(*) to COUNT(user_name)  then count number of rows 4...JDBC Select Count example In this tutorial  we will learn how work COUNT
Hibernate Criteria Count Distinct
Hibernate Criteria Count Distinct The Hibernate Criteria count distinct is used to count the number of distinct records in a table. Following a way to use... this application it will display message as shown below: select count(distinct
JPA Count Function
("SELECT COUNT(p.itemName) FROM Product p"); Number countResult=(Number... JPA Count Function       In this section, you will learn about the count function of JPA
Count Active Thread in JAVA
Count Active Thread in JAVA In this tutorial, we are using activeCount() method of thread to count the current active threads. Thread activeCount... activeCount() method. activeCount() :  This method returns the total number
Subset Tag (Control Tags) Example Using Count
the count parameter. The count parameter indicates the number of entries...Subset Tag (Control Tags) Example Using Count   .... The subset tag takes an iterator and outputs a subset of it. The parameter count
Word Count
Word Count       This example counts the number of occurrences of  a specific word.... To count it we are using countMatches() method
how to count words in string using java
++; } System.out.println("Number of words are: "+count); } } Thanks   Hello... count=0; String arr[]=st.split(" "); System.out.println("Number...how to count words in string using java  how to count words in string
PHP SQL Number of Rows
PHP SQL Number of Rows       This example illustrates how to count the rows of the table. To understand how to count the number of rows in a table, we have created a sql_num_rows.php
Get rows count and get columns names
++;                 }       System.out.println("Number of Rows present in table : "+count...);       }     } } In this program , we count the number of data rows stored...COUNT ROWS AND GET COLUMN NAMES OF A TABLE   In this program , we count
Hibernate count() Function
Hibernate count() Function In this tutorial you will learn how to use the HQL count() function count() function counts the maximum number of rows in a table however it doesn't count the null values of the specified column

Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.