Notice


AWT and SWING will be covered soon !

Tuesday, September 22, 2009

Convert String to Integer

 

public class str{
    public static void main(String args[])
    {
        String a="1";
        int x=Integer.parseInt(a);

    }
}

String Buffer

 

image

 

public class strbuf
{
    public static void main(String args[])
    {
        String str1="Hello";
        StringBuffer strbuf=new  StringBuffer(str1);
        str1= strbuf.append("World").toString();
        System.out.println(str1);
    }
}

Search Number of Occurrences in String

image

import java.util.Scanner;

public class demo{
    public static void main(String args[])
    {
        char input;
        String str_input;
        char veb;
        int count=0;
        String str="Apple";
        Scanner scan=new Scanner(System.in);
        System.out.println("Enter a String");
        str=scan.nextLine();
        System.out.println("enter the Charchter you want to Search");
        str_input=scan.next();
        input=str_input.charAt(0);
        for(int i=0;i<str.length();i++)
        {
            veb=str.charAt(i);
            if(input==veb)
            {
                count++;
            }       
        }
            System.out.println("Occurances : "+count);
    }
}