简体   繁体   English

我正在尝试在字符串数组中查找特定字符。 我必须使用什么?

[英]I am trying to find the specific character within a String Array. What must I use?

Below is the code.\\ I imagine you use a for loop and then another but I cannot seem to make it work. 下面是代码。\\我想象您使用了一个for循环,然后使用了另一个,但是我似乎无法使其正常工作。 I attempted research however most topics were too complex since I am a novice. 我尝试研究,但是由于我是新手,所以大多数主题都太复杂了。 I'm trying to find a way to get the fifth character out of each string within the variable. 我试图找到一种方法来获取变量中每个字符串的第五个字符。 I'll use the information given to me so i can then solve the rest of my program. 我将使用提供给我的信息,以便随后解决程序的其余部分。 I have more to do 我还有很多事要做

public static void main (String[]args)
    {
        String[] decoder = {"Nexa2f5", "Z52Bizlm" , "Diskapr" , "emkem9sD", "LaWYrUs", "dAStn78L", "mPTuriye", "aaeeiuUu", "IL8Ctmpn"};
        int character = 4;
        for(int i=0; i<=decoder.length-1; i++)
        {

        }
    }

I am trying to get the third and fourth characters of the odd numbered Strings. 我正在尝试获取奇数字符串的第三个和第四个字符。 I am trying to put the letters into an array and decode the message. 我正在尝试将字母放入数组并解码消息。 I am also trying to print the 5th character of all other words. 我还试图打印所有其他单词的第5个字符。 I'm having issues commenting right and I've tried to reply a couple times but no dice. 我在评论时遇到问题,我尝试过几次答复,但没有骰子。

Here is what I would do: 这是我会做的:

    String[] decoder = {"Nexa2f5", "Z52Bizlm" , "Diskapr" , "emkem9sD", "LaWYrUs", "dAStn78L", "mPTuriye", "aaeeiuUu", "IL8Ctmpn"};
    for (String s: decoder){
        String myChar = s.substring(4, 5);
        // now continue to process myChar
    }
class test {
    public static void main (String[]args)
    {
        String[] decoder = {"Nexa2f5", "Z52Bizlm" , "Diskapr" , "emkem9sD", "LaWYrUs", "dAStn78L", "mPTuriye", "aaeeiuUu", "IL8Ctmpn"};
        int character = 4;
        for(int i=0; i<=decoder.length-1; i++)
        {
        String temp = decoder[i];
        System.out.println(temp.substring(4,5));
        }
    }
}
 for(String s : decoder) {
      for(char c : s.toCharArray()) {
           //loops through ever char of every string
      }
 }

 char letter;
 for(String s : decoder) {
      if(s.length > 4) {
           letter = s.chatAt(5);
      }
 }

Choose your weapon. 选择你的武器。 I'm not completely sure how you want to do this, but this is the format you'd want for looping through variables in an array. 我不确定要如何执行此操作,但这是您要遍历数组中变量的格式。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 我正在尝试在字符串数组中查找特定字符。 我最终必须使用什么? - I am trying to find the specific character within a String Array. What must I end up using? 我正在尝试对字符串数组列表进行排序。 我使用了Collection.sort方法,但是答案是错误的 - I am trying to sort List of String array. I used Collection.sort method but answer is wrong 阵列中最长的高原。 我究竟做错了什么? - Longest plateau in array. What am I doing wrong? 为什么在尝试查看字符串是否以特定字符结尾时会出现类型不兼容的错误? - Why am I getting an incompatible types error when trying to see if a String ends with a specific character? 我试图找到字符串的反面 - i am trying to find the reverse of the string 方法未返回数组的正确值。 我究竟做错了什么? - Method not returning correct values for an array. What am I doing wrong? 我正在尝试随机播放或将输入字符串随机放置在图片上,但是我不知道要使用什么代码? - I am trying to shuffle or randomly place an input string on a picture but i have no clue on what code to use? 我正在尝试使用一种方法来查找数组中的哪个数字大于20并返回一个百分比 - I am trying to use a method in order to find which numbers in the array are greater than 20 and return a percentage 我正在尝试使用if语句进行for循环,以在arraylist中找到特定名称 - I am trying to make a for loop with a if statement in it to find a specific name in an arraylist 我正在尝试获取字符串的最后两个字符,但出现错误 - i am trying get last two character of the String but i am getting error
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM