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



Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


jenifer
java num
1 Answer(s)      3 years and 5 months ago
Posted in : Java Beginners


Write a Java program to find the number of characters in a file


Advertisement
View Answers

April 26, 2011 at 10:41 AM


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

class CountCharactersFromFile {
        public static void main(String[] args) throws Exception {
            int countch=0;
                BufferedReader br = new BufferedReader(new FileReader("C:/data.txt"));
                String strLine = "";
                String str = "";
                while ((strLine = br.readLine()) != null) {
                        str += strLine;
                }
                String st = str.replaceAll(" ", "").toLowerCase();
                char[] third = st.toCharArray();
                System.out.println("Character   Total");
                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(ch + "              " + count);
                        }
                        countch++;
                }
                System.out.println("Total number of characters: "+countch);
        }
}


Related Tutorials/Questions & Answers:
java num
java num  Write a Java program to find the number of characters in a file
find largest num enter by user using loop method - Java Interview Questions
find largest num enter by user using loop method  hi..it's me again.. thanks for answering my question.. i wanna ask, if i wanna use loop in the part: int a, b, c, d, e; Scanner in = new Scanner(System.in
Advertisements
Php Sql num rows
Php Sql num rows      .... In this example, we have created a num_rows.php file in which we executed a query..._num_rows() method.       Table:emp   Source Code
PDO Fetch Num
PDO Fetch Num: We've discussed in the previous tutorial about PDO::FETCH_ASSOC, similarly PDO provides another function which returns the numerical...;query($sql); $result=$stmt->fetch(PDO::FETCH_NUM); echo "<table
i have installed oracle 10g (both ee and xe) editions... while am installing i found port num as 1521 for ee, 1522 for xe
i have installed oracle 10g (both ee and xe) editions... while am installing i found port num as 1521 for ee, 1522 for xe  i have installed oracle 10g (both ee and xe) editions... while am installing i found port num as 1521
Num Sum
Num Sum       Easy, Sharable Web Spreadsheets, like google spreadsheets. Great for teams, clubs & your crew,Track all your group data together,Easy and super simple to use Read full
Php Sql num rows
Php Sql num rows This example illustrates how to find number of rows... and find the number of rows of the table by mysql_num_rows methods. The output... of num_rows.php  <?php   $link 
Java Program - Java Beginners
Java Program  Write a java program to find out the sum of digits... num; System.out.print("Enter a multidigit number: "); num = input.nextInt(); int sum = 0; while (num
Java Programming - Java Beginners
Java Programming  To find out minimum and maximum numbers in an array... getLargestNumber{ public static void main(String[] args) { int []num={100,20,152,24,456,651,258,35}; int max = num[0]; int min = num[0]; for (int i=1; i
JAVA PROGRAM - Java Beginners
JAVA PROGRAM  TO FIND OUT MINIMUM AND MAXIMUM NUMBERS... static void main(String[] args) { int []num={100,20,152,24,456,651,258,35}; int max = num[0]; int min = num[0]; for (int i=1; i max
java
java  how to access input as integer in java?   import... Number: "); int num=input.nextInt(); System.out.println("Entered Number is: "+num
java program - Java Beginners
java program  program to get an output i.e., is: INPUT..." }; private String oneThousand(int num) { String str; if (num % 100 < 20){ str = oneWords[num % 100]; num /= 100; } else
Java Coding Problem - Java Beginners
Java Coding Problem  Q.1 How to write a while loop that displays...[]) { int num=1; while(num<=40) { if(num%2==0) { System.out.print(" " + num + " "); } num++; } } } Solution 2 : import
java
java  write a java pgm to illustrate the keywords super,static... class instance of the current class. class Base{ protected int num; public Base(int n){ num = n; System.out.println("parameter constructor of Base class
java using Stack - Java Beginners
java using Stack  How convert decimal to binary using stack in java? whats the java program or code to that. Thank you rose india and java... the number: "); int num = input.nextInt(); Stack stack = new Stack
Java Program - Java Beginners
Java Program  Write a program to compute sum of digits of a given... = new Scanner(System.in); int num; System.out.print("Enter a multidigit number: "); num = input.nextInt
Java Code - Java Beginners
Java Code  Code the declaration for an array of ints named counts... static void main(String[] args){ int num[] = {50,20,45,82,25,63}; int l... : "); for (i = 0;i < l;i++ ){ System.out.print(" " + num[i
Java
Java  I want to practise with Java Recursive program   The recursive functions are the function which repeats itself in a java program... [] args){ int num=5; System.out.println(factorial(num
corejava - Java Beginners
num) { String str; if (num % 100 < 20){ str = oneWords[num % 100]; num /= 100; } else { str = oneWords[num % 10]; num /= 10; str = tensWords[num % 10] + str
Java
Java   i am giving the string="101",for this output is "5".Please..."; int base = 2; int num = Integer.parseInt(st, base); System.out.println(num); } } Thanks
Java Code - Java Beginners
(" " + num[i]); } } } For more example on Java visit to : http...Java Code  Code a statement that creates an array of doubles named... static void main(String[] args){ double num[] = {27.2, 33.5,12.8,56.4
java programming problem - Java Beginners
java programming problem  we are given a number ,num. ( 0<2 ) we have to represent the number(num) in the form of a,b,c,d such that: num=(a/b)*(c/d) for eg. let num=2, then a=1.5 b=0.75 c=0.4 d=0.4
Java Programming - Java Beginners
Java Programming  Write and run a program that accepts a string...{ String st = "100"; int num=Integer.parseInt(st); System.out.println("Number= "+num); } } Thanks
java - Java Beginners
java  i have to make a programm in java to multiply any number... of mathematical operators. int result=Integer.parseInt(String.valueOf(num)+"00"); // here num is the required Number. Here we are using String concatination
a java program... - Java Beginners
a java program...  write a program to check that a number...:"); int num = Integer.parseInt(bf.readLine()); int n = num; //use to check at last time int check=0,remainder; while(num > 0){ remainder = num % 10
java
java  what will be the output of the following program fragment? byte num=0; num++; ++num; System.out.println(num++);   The result is 2 as you have increment the number two times
java
;i<5;i++){ int num=array[i]; int n=num; int no=num; int sum=0; int count=0; while(num>=1){ num/=10; count++; } while(no>=1){ int rem=no%10; no/=10...[]={1631,1634,1599,1789,14784}; int a[]=new int[5]; for(int i=0;i<5;i++){ int num=array[i
a java program - Java Beginners
a java program  well sir, i just wanna ask you something regarding...)); System.out.println( " enter the number : "); int num = Integer.parseInt (br.readLine()); if (num %2==0) continue; System.out.println("this number is even :" +num
Java Program - Java Beginners
Java Program  Write a program to find the Factorial of a number using... FactorialUsingRecursion { public int findFactorial(int num) { int f; if (num < 0){ System.out.println("Error"); } if ( num ==1) return 1; f
Advertisements
 

 

 

DMCA.com