Posts which you will also like.

Sunday, September 19, 2010

Decode Window/Macintosh Error Codes

Almost every one who uses computer either novice or pro must have encountered some kind of frustrating error
code.These error show either hardware or software related issues but no one can be sure of them.
But Codes can be decoded by Error Goblin. We can look up any Windows or Mac error codes to find out what they actually mean and thereby tracing the root of cause.Error Goblin contains 16,982 error codes listed in it.
Read More ->>

Sunday, September 5, 2010

Program to Check a Palindrome String (Using Stack)

import javax.swing.JOptionPane;
class PalindromeString
{
    private char[]stack;
    private int top;
    public PalindromeString(int cap)
    {
        stack=new char[cap];
        top=-1;
    }
    public void push(char element)
    {
        stack[++top]=element;   
    }
    public char pop()
    {
        return stack[top--];
    }
    public boolean isEmpty()
    {
        return top<0;
    }
    public boolean isFull()
    {
        return top==stack.length-1;
    }
}
class palindromestringtest
{    public static void main(String []args)
    {
        String s=JOptionPane.showInputDialog(null,"Enter a String:");
        String rev="";
        PalindromeString p=new PalindromeString(s.length());
        for(int i=0;i
        {
            p.push(s.charAt(i));
        }
        while(!p.isEmpty())
        {
            rev+=p.pop();
        }
        if(rev.equals(s))
            JOptionPane.showMessageDialog(null,"String \""+s+"\" is palindrome.");
        else
            JOptionPane.showMessageDialog(null,"String \""+s+"\" is not palindrome.");
    }
}
Read More ->>

Reversing the String using Stack

import javax.swing.JOptionPane;
class stack
{
    private int top;
    private char[] stack;
    public stack(int cap)
    {   
        stack=new char[cap];
        top=-1;
    }
    public void push(char element)
    {
        stack[++top]=element;
    }
    public char pop()
    {
        return stack[top--];
    }
    public boolean isEmpty()
    {
        return top<0;
    }
    public boolean isFull()
    {
        return top==stack.length-1;
    }
   
}
class use
{
    public static void main(String []args)
    {    String revs="";
        String s=JOptionPane.showInputDialog(null,"Enter a string:");
        int len=s.length();
        stack st=new stack(len);
        for(int i=0;i
        {
            st.push(s.charAt(i));
        }
        while(!st.isEmpty())
        {
            revs+=st.pop();
        }
        JOptionPane.showMessageDialog(null,"Original String is:"+s+"\n Reversed string is:"+revs);
       
    }
}
OUTPUT:

Enter a string:Rajeev
Original String is:Rajeev
 Reversed string is:veejaR
Read More ->>

Program To Change the Case(Lower to Upper)

import javax.swing.JOptionPane;
class toupper
{   
    private String str1,str2;
    public void tuper()
    {    //str="az";
        str2="";
        str1=JOptionPane.showInputDialog(null,"Enter a string:");
        int len=str1.length();
        char ch[]=new char[len];
        ch=str1.toCharArray();
        for(int i=0;i
        {
            if(ch[i]>=97 ||ch[i]<=122)
            ch[i]-=32;
            str2+=ch[i];
                 }
               JOptionPane.showMessageDialog(null,"Original String:"+str1+"\n After Changing case:"+str2);
    }
    public static void main(String []args)
    {
        toupper t=new toupper();
        t.tuper();
       
    }
}
Read More ->>

Program To Change the Case(Upper to Lower)

import javax.swing.JOptionPane;
class tolower
{
    private String str1="";
    public void changecase()
    {
         String str2="";
        str1=JOptionPane.showInputDialog(null,"Enter a string:");
        int len=str1.length();
        char ch[]=new char[len];
        for(int i=0;i
        {    if(str1.charAt(i)>=65 && str1.charAt(i)<=90)
                ch[i]=(char)(str1.charAt(i)+32);
            else
                ch[i]=str1.charAt(i);
       
        }
        for(int i=0;i
        {
            str2+=ch[i];
        }
        JOptionPane.showMessageDialog(null,"String after changing case is:"+str2);
    }
    public static void main(String args[])
    {
        tolower t=new tolower();
        t.changecase();
    }
   
}
Read More ->>

Implementing Your Own String Function in JAVA

import javax.swing.JOptionPane;// We have imported Class JOptionPane of swing Package so that
public class CharAt                    //we can use a input and output dialog box of that class
{
    private String str,st;
    private char calc()
    {   
        str=JOptionPane.showInputDialog(null,"Enter a string:");
        st=JOptionPane.showInputDialog(null,"String you entered is:"+str+"\n Enter the index of character to find:");
        int ind=Integer.parseInt(st);
        int len=str.length();
        char ch[]=new char[len];
        ch=str.toCharArray();
        return ch[ind-1];
       
    }
    public void show()
    {   
        JOptionPane.showMessageDialog(null,"character is:"+calc());
    }
    public static void main(String []args)
    {
        CharAt a=new CharAt();
        a.show();
    }
}
OUTPUT
Read More ->>
DMCA.com Protected by Copyscape Online Plagiarism Tool