Share on Google+Share on Google+

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

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

Ads

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
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 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 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
Tutorials   
Java Spring Hibernate Struts Training What does core Java include? java What are some way to learn Java quickly? Is it required to learn Java before learning Java Script? Is it necessary to learn java script before learning PHP? Are HTML5 and Java Script boosts Java career? Is Java object oriented? Fingerprint application with Java Uninstall Oracle Virtual Box JSON to HashMap Free Java online Training I want example of Control Statement in Java ANSI Color Codes with Python Create a Program that Calculates Input What is difference between JDK,JRE and JVM? How to see ubuntu version on server? How to get Page Source in Selenium (WebDriver) using Java? The path to the driver executable must be set by the webdriver.gecko.driver system property parse data from a link in java Java Program Qns using BlueJ How to fix HAX Kernel Module Is Not Installed error? Installing Audacity Looking for code Logic to check track changes & Coments in MSWord, MSWordx, MSExcel, MSExcelx is ON/OFF Installing JDK on Mac SAX Parser exception ERROR 601 (42P00): Syntax error. Encountered Thread java.lang.NoClassDefFoundError: org/apache/commons/fileupload/FileItemFactory How to install Ubuntu 16.04 LTS? HttpServletRequest cannot be resolved to a type in eclipse - Solved Unhandled event loop exception GC overhead limit exceeded Spring Data jpa with apache phoenix Caused by: java.lang.IllegalArgumentException: Not a host:port pair: PBUF o.a.h.h.z.RecoverableZooKeeper - Possibly transient ZooKeeper, quorum= com.thinkaurelius.titan.diskstorage.hbase.HBaseStoreManager class not found com.thinkaurelius.titan.diskstorage.hbase.HBaseStoreManager not found How to download and install Java 8 on Windows? How to uninstall JDK 7? How to install gtk-doc-tools package in Ubuntu? How to install Oracle JDK 8 on Ubuntu? ejabberd_ctl.beam not found - Solved How to convert date to UTC format in Java? How to install autoconf, automake and libtool in Ubuntu 15.10? How to convert current date to mm dd yyyy format in Java? How to convert current date to dd mm yyyy format in Java? How to stop window closing in "internalFrameClosing" event. How to find list of all index in Neo4j? neo4j-server.properties file location SASLError using PLAIN: not-authorized how to convert war file into .exe file using java code

Ads

 
Advertisement null

Ads