I want to make a program that find the alphabets present in the string using java language.
e-g
i hava a string " Hello World "
It display me that charactes present in it are

H
e
l
0
w
r
d

It count a character only once.

only the alpha characters?

so H3ll0 Wor7D would print out:

H
l
l
W
o
r
D


that's easy enough to do using regular expressions.

the [a-zA-Z] searches for all characters within the range of a-zA-Z. You can then use the regexp to output the matches...etc

^ No, he's saying only to print out the character the first time it is seen.

RealThinkers, what you should do is make an array of 26 booleans, one for each letter in the alphabet. True means it has been seen, false means it hasn't. Then when you see a character, if it is a letter, check the corresponding index to see whether or not it has been seen yet. Make sure to set it to 'seen'/true after you see the char for the first time.

^ No, he's saying only to print out the character the first time it is seen.

RealThinkers, what you should do is make an array of 26 booleans, one for each letter in the alphabet. True means it has been seen, false means it hasn't. Then when you see a character, if it is a letter, check the corresponding index to see whether or not it has been seen yet. Make sure to set it to 'seen'/true after you see the char for the first time.

hah I had missed his

it count character only once

import java.io.*;
class CharAt
{

   public static void main(String[] args){

       int count=0;   

  try{
    BufferedReader object=new BufferedReader(new InputStreamReader(System.in));
    System.out.println("Enter the String");
    String s=object.readLine();
    int len=s.length();
    System.out.println(len);
 for(int i=0;i<len;i++)
{
    char char1=s.charAt(i);
    if(char1=='a')
    {
          System.out.println(char1);
          count++;

    }

    }
System.out.println("Toatal a----->" +count);
}
    catch(Exception e){}
  }
}

Edited 3 Years Ago by mike_2000_17: Fixed formatting

Comments
bumped a year old thread with a weak solution.
public class Stringtest {
    
    public Stringtest() {
    }
    static String s2;
    public static void main(String args[])
    {
        String input="My name is billa";
        String buffer=new String();
        String generated=new String();
        boolean flag;
            for(int i=0;i<input.length();i++)
            {    
               flag=true;

                for(int j=0;j<buffer.length();j++)
                {
                    if(input.charAt(i)==buffer.charAt(j))
                    {
                        flag=false;
                    }
                }
                if(flag)
                    generated=generated+input.charAt(i);
                    
                buffer=buffer+input.charAt(i);
                               
            }
        
        System.out.println(generated);
       }
}
Comments
bad code, not following naming conventions and as usefull as I am in the kitchen ..
Why did you resurrect this old thread to post this awful piece of code?

why using 26 booleans and waste memory..?

Store the string into an char array and check the repetition using a loop..

I don't think the OP is still working on this 2 years later. Closing.

Comments
if he is working on this 2yrs later there might be something wrong! :)
This article has been dead for over six months. Start a new discussion instead.