Click here to Skip to main content
15,881,882 members
Please Sign up or sign in to vote.
1.00/5 (4 votes)
See more:
using linked list the problem must be solved

Java
public class SeparateAlphabetsAndDigitsFromString {
    public static void main(String[] args) {
        String input = "a1b2c3";
        separateDigitsAndAlphabets(input);
    }
     
    public static void separateDigitsAndAlphabets(String str) {
        String number = "";
        String letter = "";
        for (int i = 0; i < str.length(); i++) {
            char a = str.charAt(i);
            if (Character.isDigit(a)) {
                number = number + a;
         
            } else {
                letter = letter + a;
             
            }
        }
        System.out.println("Alphates in string:"+letter);
        System.out.println("Numbers in String:"+number);
     
    }
} 

Output is alphabets are abc, numbers are 123


i need a suggestion to get output as mentioned in question
Posted
Updated 23-May-14 6:36am
v3
Comments
[no name] 23-May-14 6:32am    
"Do my homework assignment for me" is not a question.
Achyuth Guddeti 23-May-14 6:43am    
this is not homework or assignment. if you know have know tell me or else f*** off
[no name] 23-May-14 6:46am    
Right.... sure it's not homework. Like we have never heard that one before.
Achyuth Guddeti 23-May-14 6:47am    
if you have.... then why don;t you answer it
[no name] 23-May-14 7:14am    
Mostly because it's your homework assignment, not mine. And I don't really feel inclined to help rude abusive children.

1 solution

Happy coding! We are not going to do your own homework: try yourself and ask here just specific questions.
 
Share this answer
 
Comments
Achyuth Guddeti 23-May-14 7:03am    
public class SeparateAlphabetsAndDigitsFromString {
public static void main(String[] args) {
String input = "a1b2c3";
separateDigitsAndAlphabets(input);
}

public static void separateDigitsAndAlphabets(String str) {
String number = "";
String letter = "";
for (int i = 0; i < str.length(); i++) {
char a = str.charAt(i);
if (Character.isDigit(a)) {
number = number + a;

} else {
letter = letter + a;

}
}
System.out.println("Alphates in string:"+letter);
System.out.println("Numbers in String:"+number);

}
}

Output is alphabets are abc, numbers are 123


i need a suggestion to get output as mentioned in question
TorstenH. 23-May-14 7:25am    
I pushed the comments content into the question.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900