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



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

Have Programming Question? Ask it here!
 
 
 


Sincole Brans
Count number of "*"
2 Answer(s)      a year and 10 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);

    }

}

Advertisement
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 Tutorials/Questions & Answers:
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 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
Advertisements
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
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
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
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
Find number of words begin with the specified character
Count number of words begin with the specified character In this section, you will learn how to count the number of words that begin with the specified... with the input character. If found, counter will count the words. Here is the code
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
update count from session - Hibernate
update count from session  I need to get the count of how many rows got updated by session.saveOrUpdate(). How would I get this? Thanks, mpr
JavaScript Count Words
JavaScript Count Words In this section, you will learn how to count words... and using the regular expression, determine the number of words and finally display... that will display the number of the words in the textbox as the user enter the words
Count Palindromes from the string
by ignoring cases. If they are same, the counter will count the number...++; } } System.out.println("Number of Palindromes in the specified string: " + count...Count Palindromes from the string In this section, we are going to find out
Java xml count occurrence of elements
parsers for different purposes. Here we will count the number of occurrences...Java xml count occurrence of elements Java provides xml parsers to read... Integer(1)); } else { int count = ((Integer) value).intValue
number sorting
number sorting  program to sort a list of numbers in descending order where the inputs are entered from keyboard in runtime   Hi Friend, Try the following code: import java.util.*; class SortListInDescendingOrder
Write a query to find the total number of rows in a table
Write a query to find the total number of rows in a table  Write a query to find the total number of rows in a table?   Hi, Here is the answer, we can find the total number of rows in a table using following query
number - Java Interview Questions
number  apka number kya hai aap apna number mera id per send ker do
NUMBER OF VOWELS IN A WORD
NUMBER OF VOWELS IN A WORD  WRITE A PROGRAM THAT WILL INPUT A WORD THEN IT WILL DETERMINE THE NUMBER OF VOWELS PRESENT IN THE INPUTTED WORD
port number - JavaMail
port number  i want james2.1.3 port number like microsoft telnet>open local host _______(some port number) i wnat that port number
Count Characters from the input string Java
Count Characters from the input string of Java In this section, you will learn how to count the occurrence of each character in the string. For this, we have... to count the occurrence of each character of the array.  Here is the code
finding divisors of a number
finding divisors of a number   write a c program to input a number and print all its divisors using while loop
finding divisors of a number
finding divisors of a number   write a c program to input a number and print all its divisors using while loop
finding divisors of a number
finding divisors of a number   write a c program to input a number and print all its divisors using while loop
add number - Java Beginners
add number  Q. write a programe to add three number. The number input... input=new Scanner(System.in); System.out.println("Enter first number"); int a=input.nextInt(); System.out.println("Enter second number"); int b
Convert Number to Roman Number Using Java
Java Convert Number to Roman Numerals In this section, you will learn how to convert the number to roman number.  To do this, we have created a class... and the method convertIntegerToRoman(int n) convert the specified number into roman
Count characters from text file in Java
Count characters from text file Using Java Here we are going to count... it into character array in order to count the occurrence of each character...;ch= third[counter];   int count=0;   for 
How can i add a new count to this source code ? - Java Beginners
How can i add a new count to this source code ?  Hi everyone I... No. of found I get XTSM/XTS/TRX/XHAN and now i want count total of this ZHTYPE...); } if (xtsMap.containsKey(rec.getXts())) { Integer count = xtsMap.get
How can i add a new count to this source code ? - Java Beginners
How can i add a new count to this source code ?  Hi everyone I... No. of found I get XTSM/XTS/TRX/XHAN and now i want count total of this ZHTYPE...); } if (xtsMap.containsKey(rec.getXts())) { Integer count = xtsMap.get(rec.getXts
PHP Array Count Occurences
Array Search In PHP, array_search() function performs a search  for a value in an array, as with in_array(). If the value is found then the index position of that key (which could be string or number) will be returned
The largest integer among the X number
that prompts the user to key in a whole number X. The user is then prompted again to key in X number of integers. The program will then print out the following information : a) The largest integer among the X number of integers keyed in b
To insert maximum number of data in database.
To insert maximum number of data in database.  how to change string data type into clob data type in jsp   Hi Friend, Please visit the following link: http://www.roseindia.net/jdbc/insert-clob-example.shtml Thanks
PHP Random Number
PHP Generate Random Numbers: A random number is becoming more useful.... To generate random number, PHP provides rand() function. ... number as follows:</b>".rand(); echo "<br/><b>Same
guess number - Java Interview Questions
guess number  i am doing a java program for user to guess number. i...) { input=JOptionPane.showInputDialog("Invalid number!Please re-enter... .."); private int randomNumber; public guess2() { super("Guess Number
java number to word - Java Beginners
java number to word  Can somebody please fix this to come out with the word, not the number 23? import java.util.Scanner; public class... " + "position followed by 5 integers \nspecifying the number
Random Number Generation - Java Beginners
Random Number Generation  Can any one tell me about to generate integers that should be a 10 numbered integer. Should be between 100000000 to 9999999999. Core Application  Hi friend, Code to solve the problem
Guess Number Games in Java
Guess Number Games in Java Here we are going to create guess number game where user have to guess the randomly generated number. For this, we have allowed the user to enter any number through the textfield and click the 'try' button
Implement Complex Number Class
Implement Complex Number Class You all are aware of Complex Numbers. These numbers consists of two parts,real and imaginary which can be written in the form... are going to implement Complex Number class and perform operations on it. Here
Check Perfect Number in Java Program
How to Check Perfect Number in Java Program A perfect number is a positive... to the number itself. For example 6 is a perfect number as 1,2 and3 are its divisors... the number from the user and reports whether it is perfect or not. Here
JSTL - check odd/even number - JSP-Servlet
"this is an even (odd) number and it is in between so and so number? e.g. the random number is 4. It is an even number between 3 and 5. Much thanks all!  Hi Friend, Try the following code: Random Number: Random number
How to make auto number? - JSP-Servlet
How to make auto number?  Dear, my friend... I really need your help.... I want to ask you, how to make auto number in mysql database... number 08 = month (august) 09 = year If system of date change
PHP Float Number Format
PHP Float Number: In our daily life we use different kind of number systems... will study about Float number system. Float number system or floating point... numbers". Following examples will help you to learn floating point number precisely
How create auto number? - JSP-Servlet
How create auto number?  Dear, my friend... I really need your help.... I want to ask you, how to make auto number in mysql database... number 08 = month (august) 09 = year If system of date change to be next
How to Check Automorphic Number using Java Program
How to Check Automorphic Number using Java Program Automorphic numbers are the numbers whose square ends with the number itself or you can say it is a number whose square ends with the given integer. For example,5 is an automorphic number
how to find largest number? - Java Interview Questions
how to find largest number?  this is my java coding: import...++) { System.out.print("Enter a number: "); num=keyboard.nextInt...); } } i don't know how to add code to find the largest number.. please help
PHP Array Sizeof
PHP Array sizeof() function To count the elements of an array PHP provides.... The sizeof() & count()  functions are identical... to be count mode: 0 (by default) or 1 for COUNT_RECURSIVE
Probability Vs. Number of people table - Java Beginners
Probability Vs. Number of people table  The probability that at least... So you can see that the probability is growing as the number of people... loops we need to create a program that will show the table: probability vs. number
JavaScript for decimal number comparisons - Java Beginners
JavaScript for decimal number comparisons  Hi, I need to compare a BigDecimal in my javascript. I need a have a validation the text field value should not exceed (15,2) (max value is : 9999999999999.99). I am not able
jQuery Convert string to number
jQuery Convert string to number In this tutorial , we will discuss about how to convert string (enter into input box) into number. In this example... it from input and also need to convert into number. We can do this by following
validation of date,phone number,email - Java Beginners
validation of date,phone number,email  Sir how to validate date,phone number and email in java swings  Hi Friend, Try the following code...)"); t1=new JTextField(20); l2=new JLabel("Enter Phone Number
Validating Number Very Urgent - JSP-Servlet
Validating Number Very Urgent  Respected Sir/Madam, I am R.Ragavendran.. I want u to insert the coding for validating number in the place...; wat do u want to check? if u want to insert number only in the emp id
 

 

 

DMCA.com