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. Corba program to encrypt the text that you want to send on the client side. The server side decrypts it after receiving. Append server time.

  2. Application for counting factorial of a given number

  3. Even number ,Prime no. ,Factorial of a number

  4. Game application in CORBA for which player will guess a number between 1 to 100, which will be compared to the random number generated by the class

  5. Program to show an example of getting at characters in a String

  6. Socket program of multi client chat server

  7. Program to reverse the number eg given no : - 12345, output want :- 54321

  8. An applet program to draw different shapes

  9. Program to declare, initialize and print a StringBuffer object

  10. Program using session tracking capability of Servlets, which displays information of current user session by HttpServletRequest object

  11. Program to read the table elements into a two-dimensional array temperature

  12. Program to show an example of using user-defined package in a program

  13. An applet program to draw circle in center of the canvas

  14. Write a program for restaurant

  15. Program to ask question and accept answer up to 3 attempt and display right answer if it is wrong

  16. CORBA program for displaying the date and time of the server machine, client machine and the difference between these two date and time

  17. Develop a game application in CORBA for which the player will guess a number between 1 to 100, which will be compared to the random number generated b

  18. Program to check the start and end of a String

  19. Program that enabled applet calculator

  20. Program of inventory management and demonstrating interactive input and output

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