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

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

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 Pages:
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
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
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
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
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
java
, say num. If num is non-negative, the program should print the square root of num. However, if num is negative, the program should then print the phrase "negative
java
;i<=5;i++){ int num=input.nextInt(); if (num < min) { min = num; } if (num > max) { max = num; } } System.out.println
java
java  how to access input as integer in java?   import... Number: "); int num=input.nextInt(); System.out.println("Entered Number is: "+num
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 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
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
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 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
;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
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
addActionListener(this) in java applets program or in java Frames program  use of this keyword in addActionListener(this) in java applets program or in java Frames program.   The given code allowed the user to enter
java
: "); int num=input.nextInt(); for(int i=1;i<=10;i++){ int m=num*i; System.out.println(m
java
InterfaceExample(); ex.setData(5); int num=ex.getData(); System.out.println(num
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
for loop - Java Beginners
{ public static void main(String[] args){ int num=10000; System.out.print("Series="+num); do{ num=num/2; System.out.print(","+num); }while(num
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 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 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
) { double num[]=new double[5]; Scanner input=new Scanner(System.in...;num.length;i++){ num[i]=input.nextDouble...++){ System.out.println(num[i]); } int sum=0; int number
java
java  Write a complete Java program that prompt the user to enter TEN (10) integers and keep these integers in an array named num[]. Next display in reverse order all the integers that are greater than 15, and calculate
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 - 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
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 check highest Armstrong Number import java.util.*; class...[]=new int[5]; for(int i=0;i<arr.length;i++){ int num...("Re-enter Numbers.It is out of range."); num=input.nextInt
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
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
java  how to generate random numbers?   i want a code to store the image in mysql using JSP and JAVA pls if anyone can help me send a mail... { private static final String ALPHA_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
Java Coding - Java Beginners
Java Coding  How do I code the following: Code a while loop... = 0; int num=0; while(num<100) { count++; num = 5*count; sum = sum + num ; System.out.println(" 5 * " + count + " = "+ num
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
); double num = input.nextDouble(); int i = (int)num; String roman
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 Interview Questions
the predefined methods in java)like simple java logic. can u give the brief idea... static void main(String[] args) { int []num={10,20,152,24,456,651,258,35}; int curMax = num[0]; for (int i=1; i curMax) { curMax
java - Java Beginners
java  1-Write a computer program using java to get input from...)); System.out.println("enter the number"); int num= Integer.parseInt..."); for (int i = 1; i <= 10; i++) { System.out.println(num
Java Program - Java Beginners
Java Program  Write a program that prints prime numbers between 1...); System.out.println("Enter the end range:"); int num=input.nextInt(); String primeNo = ""; int counter = 0; System.out.println("Prime Numbers between 1 to "+num
java - Java Beginners
java  write a java programe to get the multiplication table from 1..."); int num= Integer.parseInt(object.readLine()); System.out.println...++) { System.out.println(num + " * "+i+" = "+(num*i
Java Query - Java Beginners
Java Query  Q. Write a java program to read the an array's elements... many integers you would like to enter? "); int num=in.nextInt(); int arr[]=new int[num]; for(int i=0;i
java - Java Beginners
java  Q: write a program in java which input a positive natural N... main(String[] args) { MysteriousN myth = new MysteriousN(); int num = 15; //System.out.println("Given Number = "+num); ArrayList arr = myth.find
Java Problem - Java Beginners
Java Problem  Write a program 2 input a positive integer n and check... { public static boolean isPrime ( int num ) { boolean prime = true; int limit = (int) Math.sqrt ( num ); for ( int i = 2; i <= limit; i