Find us on Google+ Kill the code

Sunday, 18 November 2012

Reverse String Dramatically in JAVA

Input    : my name is nisarg mehta
Output : mehta nisarg is name my


public class reverse_string {
    public static void main(String args[]) {
        String s = "my name is nisarg mehta";
        String output = "";
        int space = 4;
        String temp = "";
        int i = s.length();
        int j = i;
        while(space >= 0) {
            while(i>=1 && s.charAt(--i) != ' ') {
            }
            temp = s.substring(i,j);
            j = i;
            output += " " + temp;
            temp = "";
            space--;
        }
        System.out.println("Case#1 : "+output);
    }
}

Sunday, 28 October 2012

Change Background Color using Jslider in Java

This program changes the background color using the three Jslider Red, Green and Blue. it also directly change to three basic color Red, Green, Blue using JpopupMenu using right click.

Here I attach one screenshot of it.




Monday, 8 October 2012

Rail Fence Cipher with Decryption

RAIL FENCE Cipher with Decryption



#include<conio.h>
#include<stdio.h>
void main()
{
    int i,j,k=0,l=0,m=0;
    char s[20],a[10],b[10],s1[10],s2[10];
    char decry[20];
    clrscr();
    printf("enter a string:");
    scanf("%s",s);
    for(i=0;i<strlen(s);i++)
    {
        if(i%2==0)
        {
            a[k]=s[i];
            k++;
        }
        else
        {
            b[l]=s[i];
            l++;
        }
    }
    for(i=0;i<k;i++)
    {
        printf("%c ",a[i]);
        s[m]=a[i];
        m++;
    }
    for(i=0;i<l;i++)
    {
        printf(" %c",b[i]);
        s[m]=b[i];
        m++;
    }
    printf("\n");
    k=0;

    printf("\n\ncipher text is %s",s);

    //DEVCRYPTION CODE...

    printf("\n\nTaking above string as input to this code...\n\n");
    l=0;
    //s1[];
    //s2[];
    for(i=0;i<strlen(s)/2;i++) //FOR s1
    {
        s1[k++]=s[i];
    }
    k=0;
    for(;i<strlen(s);i++) s2[k++]=s[i];
    k=0;
    l=0;
    for(i=0;i<strlen(s1)+strlen(s2);i++)
    {
        if(i%2==0)
        {
            s[i]=s1[k];
            k++;
        }
        else
        {
            s[i]=s2[l];
            l++;
        }
    }
    printf("\nFINAL OUTPUT : %s",s);
    getch();
}