Showing posts with label java Codes. Show all posts
Showing posts with label java Codes. Show all posts

Monday, 10 September 2012

JAVA CODE TO GENERATE RANDOM PASSWORD

Posted by Unknown On 05:31 | No comments
public class PasswordGenerator {

static final String AB = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghijklmnopqrstuvwxyz";
    static Random rnd = new Random();

    public String randomString(int len)
    {
          StringBuilder sb = new StringBuilder(len);
           for( int i = 0; i < len; i++ )
                  sb.append( AB.charAt( rnd.nextInt(AB.length()) ) );
                System.out.println(sb);
           return sb.toString();
    }
    public static void main(String a[]){
        PasswordGenerator obj=new PasswordGenerator();
         String s=obj.randomString(6);
        System.out.println(s);
    }

Radio Button and Button Group in java

Posted by Unknown On 05:31 | No comments
 private javax.swing.JRadioButton female=new javax.swing.JRadioButton();

 private javax.swing.JRadioButton male=new javax.swing.JRadioButton();

 private javax.swing.ButtonGroup sex= new javax.swing.ButtonGroup();

  sex.add(female);

 sex.add(male);

String str;

if(male.isSelected())

str="M";
else if (female.isSelected())

str="F";


str will have the datails of the selected Butto

Tuesday, 21 August 2012

import java.io.*;
class f
{
int i,l,top=-1;
String s;
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
public void read()throws IOException
{
System.out.print("Enter the string");
s=br.readLine();
}
public void postfix()throws IOException
{
int l=s.length();
for(i=0;i<l;i++)
{
char d=s.charAt(i);
if(d>=0 && d<=9)
{
push(d);
}
else
{char c1=pop();
char c2=pop();
switch (d)
{
case '+':push(c1+c2);break;
case '-':push(c1-c2);break;
case '*':push(c1*c2);break;
case '/':push(c1/c2);break;
//case '':push(c1%c2);break;
}
}
}}
public void push(int e)
{
if (top>=(l-1))
System.out.print("Stack is full");
else
{
top++;
s[top]=e;
}}
char pop()
{
char tp;
tp=s[top];
top--;
return(tp);

}
}
class InFixPost
{
public static void main (String args[])throws IOException
{
f t=new f();
t.read();
t.postfix();
}
}





import java.io.*;
class Subp
{
int a[],n,b[],j,i;

BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
public void getData()throws IOException
{
System.out.println("enter the limit and enter the nos:");
n=Integer.parseInt(br.readLine());
a=new int[n+1];
for( i=0;i<n;i++)
{
a[i]=Integer.parseInt(br.readLine());
}}
public void display()
{
System.out.print("reverse is ");
b=new int[21];
for(i=0,j=n-1;i<n;i++,j--)
{
b[j]=a[i];
}
for(i=0,j=n;i<n;i++,j--)
{
a[i]=b[i];
System.out.print(a[i]);
}
}
}
class Array
{
public static void main(String arg[])throws IOException

{
Subp t=new Subp();
t.getData();
t.display();
}
}
class arm
{
public static void main(String arg[])
{
int n,t,s,r;
n=Integer.parseInt(arg[0]);
t=n;
s=0;
while(n>0)
{
r=n%10;
s=s+(r*r*r);
n=n/10;
}
if(t==s)
{
System.out.println("Given no. "+t+" is an armstron");
}
else
{
System.out.println("Given no. "+t+" is not anarmstron");
}
}
}

Thursday, 7 June 2012




class StarsTest
 public static void main(String args[])
 {
  int stars=1,lines=5,spaces=5;
  int i=1,j,k;
  for(i=0;i<lines;i++)
  {
   // print spaces first
  for(k=0;k<spaces;k++)
  System.out.print(" ");
for(j=0j<(stars);j++)                                 System.out.print("*"); 

Blogroll

Blogger templates

About