编写程序以实现以下目标:I / P:a-1-b-2-c-3(链接列表)O / P应为:a-b-c-1-3-2 [英] Write a program to achieve the following: I/P: a-1-b-2-c-3(Linked list) O/P should be: a-b-c-1-3-2

查看:95
本文介绍了编写程序以实现以下目标:I / P:a-1-b-2-c-3(链接列表)O / P应为:a-b-c-1-3-2的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用链表必须解决问题



using linked list the problem must be solved

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);
     
    }
} 



输出字母是abc,数字是123





i需要一个建议来获得输出的问题


Output is alphabets are abc, numbers are 123


i need a suggestion to get output as mentioned in question

推荐答案

快乐的编码!我们不打算做自己的功课:试试自己,在这里问一下具体的问题。
Happy coding! We are not going to do your own homework: try yourself and ask here just specific questions.


这篇关于编写程序以实现以下目标:I / P:a-1-b-2-c-3(链接列表)O / P应为:a-b-c-1-3-2的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆