Java Tutorial

 
 
 
 
import java.io.*;

class  countChar
{
    public static void main(String[] args) throws IOException
    {
           File f = new File(args[0]);
           FileOutputStream fos = new FileOutputStream(f);
           for (int i=0;i<5;i++ )
           {
                 fos.write((int)(Math.random()*4));
           }
           fos.close();

           FileInputStream fis = new FileInputStream(f);
           int ch;
           int c[] = new int[5];
           for (int i=0;i<c.length ;i++ )
           {
                 c[i]=0;
           }
           while((ch=fis.read())!=-1) {
                  switch (ch)
                  {
                  case 0: 
                                 c[0]=c[0]+1;
                                 break;
                  case 1:
                                 c[1]=c[1]+1;                
                                 break;
                  case 2:
                                 c[2]=c[2]+1;                  
                                 break;
                  case 3:
                                 c[3]=c[3]+1;                               
                                 break;
                 case 4:
                                 c[4]=c[4]+1;
                                 break;
                  }
                 System.out.println(ch);
            }
            System.out.println(\"\\n\\n\\nCounting of Characters\\n\");
            for (int i=0;i<c.length ;i++ )
            {
                 System.out.println(\"count for \"+i+\"    : \" +c[i]);
            }
            fis.close();
    }
}

    Related Post:
  1. Application which takes your marks of six subjects from the client side and displays the percentage that you have obtained

  2. Program to show an example of modifying String objects

  3. An applet program to add two numbers where data is entered in TextField

  4. An applet program showing Clicked Event on canvas

  5. An applet program to display Vertical Color Bar

  6. Program that enabled applet that takes name of the user. Server returns back the number in uppercase clubbed with “HELLO” and display it on applet

  7. Program to show an example of Copying i.e. Clonning Objects

  8. Program to copy the elements of an array into another array in reverse order and print them

  9. Program to show an example of Polymorphism

  10. Define an array of ten String elements each containing an arbitrary string of the form “month/day/year”

  11. Program to show the use of Switch Statement for the same statement for several different case labels

  12. Corba program to Write a Echo server and client with UDP server and client

  13. Develop a simple calculator with addition, subtraction, multiplication and division capabilities, data collection from client side, executed on server

  14. Program to declare, initialize and print an array of characters

  15. An applet program that display blinking rectangle

  16. Program to show the use of operator (&lt;&lt;) Shift Left filling with zero from the right

  17. Dialog Boxes

  18. Program that will read real number from the keyboard and print the following output in one line: small Integer not less The Given Number Largest Int

  19. Program to show the use of Switch Statement

  20. Program to declare, initialize and print a 2D array of integers

 
 
Didn't find what you were looking for? Find more on File handling program to count number of characters in a file