class extra
{
public static void main(String args[])
{
hexadecimal h=new hexadecimal();
int a1,a2=0;
char c;
a1=Integer.parseInt(args[0]);
//System.out.println(h.hax(a1,a2));
h.hax(a1);
}
}
class hexadecimal
{
void hax(int a1)
{
int b;
char c;
b=a1%16;
a1=a1/16;
if(a1>16)
{
hax(a1);
}
System.out.print(a1);
if(b==0 && a1<16)
{
System.out.print(0);
}
if(b>9)
{
c=(char)(b+55);
System.out.print(c);
}
else
{
System.out.print(b);
}
return;
}
}
Monday, 26 March 2012
Decimal to Hexadecimal convertor (10to16 convertor)using JAVA
Thursday, 22 March 2012
Sticky Oval in JAVA
import java.awt.*;
import java.awt.event.*;
import java.applet.*;
public class sticky_oval extends Applet implements MouseMotionListener {
int x,y;
public void init() {
addMouseMotionListener(this);
}
public void mouseMoved(MouseEvent me) {
x=me.getX();
y=me.getY();
repaint();
}
public void mouseDragged(MouseEvent me) {
}
public void paint(Graphics g) {
try {
g.drawOval(x,y,x,y);
if(x==y) {
g.setColor(Color.blue);
g.fillOval(x,y,x,y);
showStatus("THIS IS PERFECT CIRCLE.");
Thread.sleep(4000);
} else showStatus("");
} catch(InterruptedException e) {
}
}
}
Saturday, 17 March 2012
Calculator using Buttons in JavaScript
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
<style type="text/css">
.box {
width:15px;
height:15px;
}
</style>
</head>
<body>
<script type="text/javascript">
var no1="",no2="";
var flag=0;
var flag2=0;
var already=0;
function calc(id,txt)
{
if(flag==0)
{
no1=no1+document.getElementById(id).value;
document.getElementById(txt).value=no1;
}
else if(flag==1)
{
no2=no2+document.getElementById(id).value;
document.getElementById(txt).value=no2;
}
}
function change(id)
{
if(already==0)
{
flag=1;
already=1;
var sign=document.getElementById(id).value;
if(sign=='+')
{
if(flag2==0) document.getElementById('one').value=document.getElementById('two').value;
document.getElementById('one').value=document.getElementById('one').value+"+";
flag2=1;
}
if(sign=='-')
{
if(flag2==0) document.getElementById('one').value=document.getElementById('two').value;
document.getElementById('one').value=document.getElementById('one').value+"-";
flag2=1;
}
if(sign=='*')
{
if(flag2==0) document.getElementById('one').value=document.getElementById('two').value;
document.getElementById('one').value=document.getElementById('one').value+"*";
flag2=1;
}
if(sign=='/')
{
if(flag2==0) document.getElementById('one').value=document.getElementById('two').value;
document.getElementById('one').value=document.getElementById('one').value+"/";
flag2=1;
}
document.getElementById('two').value="";
}
}
function ans(id)
{
var txt1=document.getElementById('one').value;
var no1=txt1.substr(0,txt1.length-1);
var no2= document.getElementById('two').value;
flag=3;
<!--var no2=document.getElementById('two').value;-->
<!--var txt1=document.getElementById('one').value;-->
<!--var no2=no1.substr(0,txt1.length-2);-->
no1=parseInt(no1);
no2=parseInt(no2);
if(txt1.charAt(txt1.length-1)=='+') document.getElementById('ans').value=(no1+no2);
if(txt1.charAt(txt1.length-1)=="-") document.getElementById('ans').value=(no1-no2);
if(txt1.charAt(txt1.length-1)=="*") document.getElementById('ans').value=(no1*no2);
if(txt1.charAt(txt1.length-1)=="/")
{
try
{
if(no2!=0) document.getElementById('ans').value=(no1/no2);
else document.getElementById('ans').value="Error while dividing";
}
catch(err)
{
document.getElementById('ans').value="by Zero is not possible";
}
}
}
function clear1()
{
document.getElementById('one').value="no1";
document.getElementById('two').value="no2"
document.getElementById('ans').value="answer";
no1="";
no2="";
flag=0;
flag2=0;
already=0;
}
</script>
<input type="text" id="one" readonly="readonly" value="no1"/><br />
<input type="text" id="two" readonly="readonly" value="no2"/><br />
<input type="text" id="ans" value="answer" readonly="readonly" />
<table width="30%" cellpadding="0" cellpadding="0">
<tr>
<td><input type="button" id="01" value="1" onclick="return calc(this.id,'two')"/>
<input type="button" id="2" value="2" onclick="return calc(this.id,'two')"/>
<input type="button" id="3" value="3" onclick="return calc(this.id,'two')"/>
<input type="button" id="add" value="+" onclick="return change(this.id)" />
</td>
</tr>
<tr>
<td>
<input type="button" id="4" value="4" onclick="return calc(this.id,'two')"/>
<input type="button" id="5" value="5" onclick="return calc(this.id,'two')"/>
<input type="button" id="6" value="6" onclick="return calc(this.id,'two')"/>
<input type="button" id="sub" value="-" onclick="return change(this.id)" />
</td>
</tr>
<tr>
<td>
<input type="button" id="7" value="7" onclick="return calc(this.id,'two')"/>
<input type="button" id="8" value="8" onclick="return calc(this.id,'two')"/>
<input type="button" id="9" value="9" onclick="return calc(this.id,'two')"/>
<input type="button" id="mul" value="*" onclick="return change(this.id)" />
</td>
</tr>
<tr>
<td>
<input type="button" id="c" value="C" onclick="return clear1()"/>
<input type="button" id="0" value="0" onclick="return calc(this.id,'two')"/>
<input type="button" id="equal" value="=" onclick="return ans(this.id)"/>
<input type="button" id="div" value="/" onclick="return change(this.id)" />
</td>
</tr>
</table>
</body>
</html>
Tuesday, 13 March 2012
Dynamic Finite Automata for String Validation in C
#include<conio.h>
#include<stdio.h>
void main()
{
int tab[10][10], i, j, k, t=65, b, r, c, l=0;
char s[20], t1[50];
clrscr();
printf("enter rows and cols : ");
scanf("%d",&r);
scanf("%d",&c);
printf("enter your state transition table : ");
scanf("%s",t1);
for(i=0; i<r; i++)
{
for(j=0; j<c; j++)
{
tab[i][j]=t1[l];
l++;
}
}
for(i=0; i<r; i++)
{
for(j=0; j<c; j++)
{
printf("%c", tab[i][j]);
}
printf("\n");
}
printf("enter a string : ");
scanf("%s",s);
for(i=0; i<strlen(s); i++)
{
for(k=0; k<r; k++)
{
if(t==tab[k][0]) b=k;
}
if(s[i]=='0')
{
t=tab[b][1];
}
if(s[i]=='1')
{
t=tab[b][2];
}
}
if(t==tab[r-1][0]) printf("valid");
else printf("invalid");
getch();
}
Monday, 12 March 2012
Count the number of Checkboxes selected
| Subject | one two three four five |
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
</head>
<body>
<script type="text/javascript">
var i=0;
function isset(id) {
var n=document.getElementById(id);
if(n.checked==true) {
i++;
}
else {
i--;
}
}
function validate() {
document.getElementById('lbl').innerHTML=i+" Checkbox Selected";
}
</script>
<table width="100%"><br />
<tr>
<td width="20%">Subject </td>
<td> <input type="checkbox" id="1" onclick="return isset(this.id)" />one
<input type="checkbox" id="2" onclick="return isset(this.id)" />two
<input type="checkbox" id="3" onclick="return isset(this.id)" />three
<input type="checkbox" id="4" onclick="return isset(this.id)" />four
<input type="checkbox" id="5" onclick="return isset(this.id)" />five
</td>
<td> <input type="button" onclick="return validate()" value="Check"/> </td>
<td> <label id="lbl"> </label> </td>
</tr>
</table>
</body>
</html>
Sunday, 11 March 2012
Palindrome validation in Javascript
Preview :
New Web Project
Enter a string :
Code :
Code :
<html>
<head>
<title>New Web Project</title>
</head>
<body>
<script type="text/javascript">
function pal() {
var b;
var a = document.getElementById('str');
var c1 = a.value.length;
var flag=0;
for(b=0; b<c1/2;b++) {
if(a.value.charAt(b)==a.value.charAt(--c1)) {
flag=0;
}
else {
flag=1;
break; } } if(flag!=1) { document.getElementById("lbl").innerHTML = "The string is Palindrome"; document.getElementById("fnt").style.color = "green"; } else { document.getElementById("lbl").innerHTML = "The string is not Palindrome"; document.getElementById("fnt").style.color = "red"; } return; } function foc() { var a = document.getElementById("str"); if(a.value == "enter string...") a.value = ""; return; } function foc_lost() { var b = document.getElementById("str"); if(b.value == "") b.value = "enter string..."; return; } </script> Enter a string : <input type="text" name="string" id="str" value="enter string..." onfocus="return foc()" onblur="return foc_lost()"/> <input type="button" onclick="return pal()" value="Check"/><br /> <font id="fnt"><label id="lbl"></label></font> </body> </html>
Thursday, 8 March 2012
Draw Table with required rows and cols in JAVA
import java.awt.*;
import java.applet.*;
import java.awt.event.*;
/*
<applet code="mousemotion" width=400 height=400>
</applet>
*/
public class mousemotion extends Applet implements MouseMotionListener,MouseListener {
String name="NISARG";
//String dim=" ";
int mx,my,mx2,my2,mx1,my1,mx3,my3;
int reles=0,dragged=0,drg_reles=0,rls_aftr_drg=0,clr_screen=0;
int ROW=12;
int COLOUM=12;
public void init() {
addMouseMotionListener(this);
addMouseListener(this);
}
public void mouseClicked(MouseEvent me) {
showStatus("MOUSE CLICKED.");
clr_screen=1;
repaint();
}
public void mousePressed(MouseEvent me) {
mx1=me.getX();
my1=me.getY();
}
public void mouseEntered(MouseEvent me) {
showStatus("SHOW STATUS.");
}
public void mouseReleased(MouseEvent me) {
if(dragged==1) {
drg_reles=1;
}
mx2=me.getX();
my2=me.getY();
dragged=0;
reles=1;
repaint();
}
public void mouseExited(MouseEvent me) {
showStatus("MOUSE EXITED.");
}
public void mouseDragged(MouseEvent me) {
showStatus("Mouse is at "+me.getX()+" "+me.getY());
mx3=me.getX();
my3=me.getY();
rls_aftr_drg=1;
//drg_reles=1;
dragged=1;
repaint();
}
public void mouseMoved(MouseEvent me) {
showStatus("Mouse is at "+me.getX()+" "+me.getY());
}
public void paint(Graphics g) {
if(clr_screen==1) {
clr_screen=0;
}
else if(reles==1 && dragged==1) { //MOUSE RELEASED.
g.drawLine(mx1,my1,mx2,my1);
g.drawLine(mx1,my1,mx1,my2);
g.drawLine(mx1,my2,mx2,my2);
g.drawLine(mx2,my1,mx2,my2);
int ROW11=(my3-my1)/ROW;
int ROW111=ROW11;
ROW11+=my1;
int COLOUM11=(mx3-mx1)/COLOUM;
int COLOUM111=COLOUM11;
COLOUM11+=mx1;
for(int i=0;i<ROW;i++) {
g.drawLine(mx1,ROW11,mx3,ROW11);
ROW11+=ROW111;
}
//g.drawLine(mx1,ROW11,mx3,ROW11);
for(int j=0;j<COLOUM;j++) {
g.drawLine(COLOUM11,my1,COLOUM11,my3);
COLOUM11+=COLOUM111;
}
reles=0;
}
else if(rls_aftr_drg==1) { //MOUSE DRAGGED.
g.drawLine(mx1,my1,mx3,my1);
g.drawLine(mx1,my1,mx1,my3);
g.drawLine(mx1,my3,mx3,my3);
g.drawLine(mx3,my1,mx3,my3);
int ROW11=(my3-my1)/ROW;
int ROW111=ROW11;
ROW11+=my1;
int COLOUM11=(mx3-mx1)/COLOUM;
int COLOUM111=COLOUM11;
COLOUM11+=mx1;
for(int i=0;i<ROW;i++) {
g.drawLine(mx1,ROW11,mx3,ROW11);
ROW11+=ROW111;
}
for(int j=0;j<COLOUM;j++) {
g.drawLine(COLOUM11,my1,COLOUM11,my3);
COLOUM11+=COLOUM111;
}
dragged=0;
//rls_aftr_drg=0;
}
if(drg_reles==1) { //MOUSE RELEASED.
g.drawLine(mx1,my1,mx2,my1);
g.drawLine(mx1,my1,mx1,my2);
g.drawLine(mx1,my2,mx2,my2);
g.drawLine(mx2,my1,mx2,my2);
int ROW11=(my3-my1)/ROW;
int ROW111=ROW11;
ROW11+=my1;
int COLOUM11=(mx3-mx1)/COLOUM;
int COLOUM111=COLOUM11;
COLOUM11+=mx1;
for(int i=0;i<ROW;i++) {
g.drawLine(mx1,ROW11,mx3,ROW11);
ROW11+=ROW111;
}
for(int j=0;j<COLOUM;j++) {
g.drawLine(COLOUM11,my1,COLOUM11,my3);
COLOUM11+=COLOUM111;
}
drg_reles=0;
}
}
}
Wednesday, 7 March 2012
Ball rolling in the TUNNEL
/* Make the ball float in tunnel and apply password mechanism...*/
import java.awt.*;
import java.applet.*;
import java.awt.event.*;
/*
<applet code="rolling_fun12" width=1000 height=300>
</applet>
*/
public class rolling_fun12 extends Applet implements Runnable,KeyListener {
String msg="";
String password="nisarg"; /*THIS IS YOUR PASSWORD STRING...*/
char c;
boolean correct=false;
int i=0;
int finish=0;
public void init() {
addKeyListener(this);
requestFocus();
t=new Thread(this);
}
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(finish==1) showStatus("THE OUTPUT IS ON THE SCREEN.");
else if(msg.equals(password)) {
showStatus("VALID PASSWORD.");
repaint();
}
}
public void keyTyped(KeyEvent ke) {
if(finish==1) showStatus("THE OUTPUT IS ON THE SCREEN.");
else {
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.");
}
repaint();
}
}
Thread t;
int start=180;
int end=350;
int x=300;
int y=225;
int end1=0,end2=0,end3=0;
int flag=0,flag2=0;
int slide1=0,drop=0,slide2=0,remain=0,enter=0,once=0;
Color c1=new Color(255,0,255);
/*public void init() {
t=new Thread(this,"first");
}*/
public void start() {
t.start();
}
public void run() {
for(;;) {
if(end3<1460) {
slide2=1;
repaint();
}
else if(end2<1650) {
drop=1;
slide2=0;
repaint();
}
else if(end1<1350) {
drop=0;
slide1=1;
repaint();
}
else {
remain=1;
slide1=0;
slide2=0;
drop=0;
repaint();
}
}
}
public void paint(Graphics g) {
if(correct) {
g.drawLine(15,100,150,100);
g.drawLine(150,100,150,260);
g.drawLine(151,260,325,260);
g.drawLine(200,58,200,218);
g.drawLine(15,58,200,58);
g.drawLine(326,260,326,219);
g.drawLine(326,218,200,218);
if(slide1==1)
{
try {
start=start+15;
end=end+15;
//g.drawArc(x,59,40,40,start,360);
g.setColor(c1);
if(enter==0) {
g.fillArc(x,y,40,40,/*start*/0,360);
enter=1;
}
else {
g.fillArc(x,y,40,40,/*start*/start,353);
enter=0;
}
x=x-5;
if(start>350) {
start=0;
end=350;
}
//if(x>230) x=10;
//if(end1<1350)
//{
end1+=50;
Thread.sleep(60);
slide1=0;
repaint();
//showStatus("end = "+end);
//}
//flag2=1;
} catch(InterruptedException e) {
showStatus("ERROR");
}
}
if(drop==1) {
try {
start=start+15;
end=end+15;
//x=155;
//y=y+40;
//g.drawArc(x,y,40,40,start,360);
g.setColor(c1);
if(enter==0) {
g.fillArc(x+2,y,40,40,/*start*/0,360);
enter=1;
}
else {
g.fillArc(x+2,y,40,40,/*start*/start,353);
enter=0;
}
y=y-5;
if(start>350) {
start=0;
end=350;
}
//if(y>295) y=150;
//if(end2<700)
//{
end2+=50;
drop=0;
repaint();
//showStatus("end = "+end);
Thread.sleep(100);
//}
} catch(InterruptedException e) {
showStatus("ERROR");
}
}
if(slide2==1)
{
try {
start=start-15;
end=end+15;
//g.drawArc(x,y-5,40,40,start,360);
g.setColor(c1);
if(enter==1) {
g.fillArc(x,y-5,40,40,/*start*/0,360);
enter=0;
}
else {
g.fillArc(x,y-5,40,40,/*start*/start,353);
x=x-5;
}
if(start>350) {
start=0;
end=350;
}
//if(x>230) x=10;
//if(end1<1350)
//{
end3+=50;
Thread.sleep(60);
slide1=0;
slide2=0;
repaint();
//showStatus("end = "+end);
//}
//flag2=1;
} catch(InterruptedException e) {
showStatus("ERROR");
}
}
if(remain==1) {
//g.drawArc(x-5,y-5,40,40,0,360);
g.setColor(c1);
finish=1;
if(once==0) {
showStatus("PROGRAM ENDED.");
once=1;
}
g.fillArc(x+5,y,40,40,0,360);
try {
Thread.sleep(500);
} catch(InterruptedException e) {
}
}
}
else {
g.drawString("ENTER VALID PASSWORD.",40,40);
try {
Thread.sleep(3000);
} catch(InterruptedException e) {
}
}
}
}
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);
}
}
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);
}
}
Image changer in Javascript using Z-Index
Preview :
New Web Project
Code :

Code :
<html><head> <title>New Web Project</title> <style type="text/css"> #block img { position:absolute; left:10px; top:10px; z-index:0; } #but { margin-left: 300px; margin-top: 300px; } </style> </head> <body> <script type="text/javascript"> var b = 0; function change() { b++; var a = document.getElementById(b%5); a.style.zIndex = b; return; } function call() { var c = setInterval("change()",1000); return; } </script> <div id="block"> <img src="4.png" id="4"/> <img src="3.png" id="3"/> <img src="2.png" id="2"/> <img src="1.png" id="1"/> </div> <input type="button" id="but" onclick="return call()" value="change"> </body> </html>
Thursday, 1 March 2012
Image Swaping in Javascript
Preview :
New Web Project
Code :
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>New Web Project</title>
</head>
<body>
<script type="text/javascript">
function swap() {
var t = document.getElementById("i1").src;
document.getElementById("i1").src = document.getElementById("i2").src;
document.getElementById("i2").src = t;
return;
}
</script>
<img src="1.png" id="i1"/>
<img src="2.png" id="i2"/>
<input type="button" id="but" value="swap" onclick="return swap()"/>
<a href="http://killthecode.blogspot.in">For more programs click here</a>
</body>
</html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>New Web Project</title>
</head>
<body>
<script type="text/javascript">
function swap() {
var t = document.getElementById("i1").src;
document.getElementById("i1").src = document.getElementById("i2").src;
document.getElementById("i2").src = t;
return;
}
</script>
<img src="1.png" id="i1"/>
<img src="2.png" id="i2"/>
<input type="button" id="but" value="swap" onclick="return swap()"/>
<a href="http://killthecode.blogspot.in">For more programs click here</a>
</body>
</html>
Subscribe to:
Comments (Atom)