Java Program to separate vowels & consonants in a File.

PROGRAM   DESCRIPTION: This Program creates one file which stores a String. It separates the input String into vowels and consonants and stores them in two different File. Here one extra File is used to store nonalphabate values. Sample Output: CODE: import java.io.*;import java.util.*;class File1 { public static void main(String[] args) throws Exception { Scanner sc=new Scanner(System.in); System.out.println(“Enter a String:”); String data1=sc.nextLine(); FileOutputStream fos=new FileOutputStream(“abc.txt”); byte[] b1=data1.getBytes(); fos.write(b1); FileInputStream fis=new FileInputStream(“abc.txt”); int size=fis.available(); byte[] b2=new byte[size]; fis.read(b2); String data2=new String(b2); FileOutputStream fos1=new FileOutputStream(“vowels.txt”); FileOutputStream fos2=new FileOutputStream(“consonants.txt”); FileOutputStream fos3=new FileOutputStream(“nonalphabets.txt”); for(int…

Read More

Getting Form Data through Java Script

This is a simple code snippet in which you will be able to retrieve data from the form using JS. This is a basic Js stuff, which you should know how to use. Basically in this code snippet, there in a HTML form element which has 2 text type input box and a button which calls the JS function. Screenshot The JS Function has a Form Element which takes the values from the input elements and then appends it inside a paragraph and shows ! The Code <!–The CSS For…

Read More

Merging two files into one file

Some time we need to merge two or more file written by many ones. Then we can simply use such a lite and small program to merge many files into one. Screenshots: The output of the program View of the file one View the file two View the merged file here The code: #include<iostream>#include<fstream>#include<string.h>using namespace std;int main(int argc, char *argv[]){ if ( argc != 4 ) cout<<“give 3 file as command line argument”<<endl; else { ifstream file1; /*object created for file1*/ file1.open(argv[1]); /*Name of the file1 passed through command line…

Read More

Program to find strings are “anagram” or not

                                 This is a program which uses java concept to find out the given strings are anagram or not. Well, anagram is a concept in which two strings will be having same alphabets but the spelling would be different. This program uses String class to declare objects and the methods used are accordingly to check the strings. Look at the sample output and the code given below. Sample Output: Program Code: import java.util.*;class AnagramEx{ public…

Read More

File Handling in Cpp [Read & Write]

This is a program which will perform the File Handling operations in Cpp program. In this a txt file, data.txt is created in which the input is stored and then read and displayed. Screenshots [Demo] The Terminal window in which the data is entered and then fetched The file data.txt, generated by the program ! The Code #include<iostream>#include<fstream>using namespace std;int main(){ fstream fp; char st[50]; fp.open(“data.txt”,ios::out|ios::binary); for (int i=0;i<4;i++) { cout<<“Enter THe String: “; gets(st); fp<<st<<endl; } fp.close(); fp.open(“data.txt”); cout<<“Displaying the File: “; while (!fp.eof()) { fp>>st; cout<<st<<” “; }…

Read More

Chat application in C using named PIPES

This is a simple set of two C Programs which can act as a chat application. Basically there are two programs which need to run simultaneously. One is the client program and other the server program. This core concept used behind this is FIFO, named pipes. Screenshots [Demo] Client Side Chat Terminal running the client output file Server Side Chat Terminal running the server output file The Code–> Receiver(Server) Side code //client_chat#include<stdio.h>#include<stdlib.h>#include<sys/stat.h>#include<unistd.h>#include<string.h> #include<linux/stat.h>#define FIFO_FILE “MYFIFO”int main(){ FILE *fp; char a[40]; char readbuf[80]; start: if((fp=fopen(FIFO_FILE,”r+”))==NULL) { perror(“fopen”); exit(1); } printf(“Me :…

Read More

How to calculate the time required to execute a particular program

The following program shows how to calculate the time taken to execute a program. The program is implemented using c. Here <time.h> header file is included. Output :  Code : #include<stdio.h>#include<time.h>int main(){ int i; clock_t begin,end; begin=clock(); for(i=0;i<5;i++) { printf(“Hello worldn”); } end=clock(); printf(“Time taken : %lfn”,(double)(end-begin)/CLOCKS_PER_SEC); return 0;}

Read More

Constructor overloading in C++

                          Well hello guys, I am back again with a key concept of C++ programming language. This program is all about constructor overloading concept. Even if it is a very simple concept, one should have knowledge on it. Have a look at the concept explained below. Concept:                            Constructor is a special feature in C++ whose task is to initialize objects of its class. It is…

Read More

Hackerrank Sherlock and array solution

The below program is the solution of Sherlock and array in hackerrank. Screenshot[Demo] :  Code : #include<iostream>using namespace std;int main(){ int t; cin>>t; while(t–) { int x,l=0,r=0,flag=0; cin>>x; int a[x]; for(int i=0;i<x;i++) { cin>>a[i]; r+=a[i]; } for(int i=0;i<x;i++) { l=l+a[i-1]; r=r-a[i]; cout<<l<<” “<<r<<” “<<i<<endl; if(l==r) { flag=1; break; } } if(flag==1) cout<<“YES”<<endl; else cout<<“NO”<<endl; }}

Read More

How multitasking or multi-threading is working in Java

Java supports the multi tasking concept using time sharing concept of CPU. It switch from one task to another task in the midway. We can control the switching time using sleep or wait method.It’s a totally random process, we cannot predict the order. Screenshot/Output: Using the try block (sleep method) Without using the try block (sleep method) The Code: class Demo1 extends Thread{ public void run() { for(int i=0;i<10;i++) { System.out.println(“Thread 1 “+i); /*try { Thread.sleep(200); } catch(InterruptedException e) { System.out.println(e); }*/ } }}class Demo2 extends Thread{ synchronized public void…

Read More