Find us on Google+ Kill the code: set
Showing posts with label set. Show all posts
Showing posts with label set. Show all posts

Friday, 14 December 2012

String sorting in JAVA

ublic class string_sort {
        static String input[] = {"abcdefgh","abcdefg","abcdef","abcde","abcd","abcz","ab","bat", "basd", "ba", "bas","abcdefgh","abcdefg","abcdef","abcde","abcd","abcz","ab","bat", "basd", "ba", "bas"};
   
    static int max = input[0].length();
   
    public static void main(String args[]) {
        findMax();
        int[] all = {0,0};
        int k =0;
        int size = input.length;
            for(int i=0;i<size;i++) {
                for(int j=0;j<size;j++) {
                    if(input[i].compareTo(input[j]) < 0) {
                        swap(i,j);
                    }      
                }
            }
        for(int i=0;i<size;i++) {
            System.out.println("" + input[i]);
        }       
    }
static void swap(int i,int j) {
        String temp = "";
        temp = input[i];
        input[i] = input[j];
        input[j] = temp;
    }  
}

Sunday, 4 March 2012

Set Password using JAVA

//This program lets you the password and access the data as soon as you type the //correct password..without pressing ENTER...





import java.awt.*;
import java.applet.*;
import java.awt.event.*;


/*
<applet code="password_setter" width=400 height=400>
</applet>
*/


public class password_setter extends Applet implements KeyListener {
String msg="";
String password="PASSWORD";  // Write your Password here....
char c;
boolean correct=false;
int i=0;
public void init() {
addKeyListener(this);
requestFocus();
}
public void keyPressed(KeyEvent ke) {
showStatus("key Pressed.");
/*c=ke.getKeyChar();
check=true;
if(c==password.charAt(i++)) {
msg=msg+c;
}
else {
msg="";
i=0;
}*/
//if(msg.equals(password)) showStatus("VALID PASSWORD.");
//showStatus("key Pressed.");
}
public void keyReleased(KeyEvent ke) {
if(msg.equals(password)) showStatus("VALID PASSWORD.");
}
public void keyTyped(KeyEvent ke) {
showStatus("Key Typed.");
//showStatus("Key Typed.");
c=ke.getKeyChar();
if(c==password.charAt(i++)) {
msg=msg+c;
}
else {
msg="";
i=0;
}
if(msg.equals(password)) {
correct=true;
repaint();
showStatus("VALID PASSWORD.");
}
}
public void paint(Graphics g) {
if(correct) g.drawString("YOU HAVE ENTERED CORRECT PASSWORD.",40,40);
}
}