1. <legend id='Ex5i2'><style id='Ex5i2'><dir id='Ex5i2'><q id='Ex5i2'></q></dir></style></legend>
    2. <i id='Ex5i2'><tr id='Ex5i2'><dt id='Ex5i2'><q id='Ex5i2'><span id='Ex5i2'><b id='Ex5i2'><form id='Ex5i2'><ins id='Ex5i2'></ins><ul id='Ex5i2'></ul><sub id='Ex5i2'></sub></form><legend id='Ex5i2'></legend><bdo id='Ex5i2'><pre id='Ex5i2'><center id='Ex5i2'></center></pre></bdo></b><th id='Ex5i2'></th></span></q></dt></tr></i><div id='Ex5i2'><tfoot id='Ex5i2'></tfoot><dl id='Ex5i2'><fieldset id='Ex5i2'></fieldset></dl></div>
    3. <small id='Ex5i2'></small><noframes id='Ex5i2'>

      <tfoot id='Ex5i2'></tfoot>

        <bdo id='Ex5i2'></bdo><ul id='Ex5i2'></ul>

        比较时忽略char上的大写和小写

        时间:2023-07-27

            <tfoot id='gcw3S'></tfoot>
              • <bdo id='gcw3S'></bdo><ul id='gcw3S'></ul>

                <small id='gcw3S'></small><noframes id='gcw3S'>

                1. <legend id='gcw3S'><style id='gcw3S'><dir id='gcw3S'><q id='gcw3S'></q></dir></style></legend>
                    <tbody id='gcw3S'></tbody>
                  <i id='gcw3S'><tr id='gcw3S'><dt id='gcw3S'><q id='gcw3S'><span id='gcw3S'><b id='gcw3S'><form id='gcw3S'><ins id='gcw3S'></ins><ul id='gcw3S'></ul><sub id='gcw3S'></sub></form><legend id='gcw3S'></legend><bdo id='gcw3S'><pre id='gcw3S'><center id='gcw3S'></center></pre></bdo></b><th id='gcw3S'></th></span></q></dt></tr></i><div id='gcw3S'><tfoot id='gcw3S'></tfoot><dl id='gcw3S'><fieldset id='gcw3S'></fieldset></dl></div>

                  本文介绍了比较时忽略char上的大写和小写的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  这样做的目的是从用户那里得到一个句子并确定每个元音出现了多少.除了我不确定如何忽略大写和小写字母但我猜是 equalsIgnoreCase 或 toUpperCase().

                  The goal of this is to get a sentence from the user and determine how many of each vowel shows up.The majority of this is done except I am not sure how to ignore uppercase and lowercase letters but I am guessing equalsIgnoreCase or toUpperCase().

                  我还想知道是否有其他方法可以使用其他一些 StringStringBuilderCharacter 类.我对编程还是很陌生,这一章让我很生气.

                  I'd like to also know if there is another way to do this using some other classes of String, StringBuilder, or Character. I'm still new to programming and this chapter is killing me.

                      int counterA=0,counterE=0,counterI=0,counterO=0,counterU=0;
                      String sentence=JOptionPane.showInputDialog("Enter a sentence for vowel count");        
                  
                      for(int i=0;i<sentence.length();i++){
                          if(sentence.charAt(i)=='a'){
                              counterA++;}
                          else if(sentence.charAt(i)=='e'){
                              counterE++;}
                          else if(sentence.charAt(i)=='i'){
                              counterI++;}
                          else if(sentence.charAt(i)=='o'){
                              counterO++;}
                          else if(sentence.charAt(i)=='u'){
                              counterU++;}
                          }   
                      String message= String.format("The count for each vowel is 
                  A:%d
                  E:%d
                  I:%d
                  O:%d
                  U:%d",
                              counterA,counterE,counterI,counterO,counterU);  
                      JOptionPane.showMessageDialog(null, message);
                  }
                  

                  }

                  代码在这里

                  推荐答案

                  由于你是在原始字符上进行比较,

                  Since you are comparing on primitive char,

                  Character.toLowerCase(sentence.charAt(i))=='a'      
                  Character.toUpperCase(sentence.charAt(i))=='A' 
                  

                  应该已经是您在 Java 中的最佳方式了.

                  should already be the best way for your case in Java.

                  但是如果你在 Stirng 上进行比较

                  But if you are comparing on Stirng

                   sentence.substring(i,i+1).equalsIgnoreCase("a")
                  

                  会更直接,但有点难以阅读.

                  will be more direct , but a little bit harder to read.

                  如果数组或列表中有 String 类型,则调用

                  If you have a String type inside an array or list, calling

                  s.equalsIgnoreCase("a") 
                  

                  会好很多.请注意,您现在是在与a"而不是a"进行比较.

                  will be much better. Please note that you are now comparing with "a" not 'a'.

                  如果你使用StringBuilder/StringBuffer,你可以调用toString(),然后使用同样的方法.

                  If you are using StringBuilder/StringBuffer, you can call toString(), and then use the same method.

                  sb.toString().substring(i,i+1).equalsIgnoreCase("a");
                  

                  这篇关于比较时忽略char上的大写和小写的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:java - 如何检查Java句子中有多少个辅音和元音? 下一篇:Java中字符串字符的结尾

                  相关文章

                  最新文章

                2. <tfoot id='TM4f2'></tfoot>

                      <legend id='TM4f2'><style id='TM4f2'><dir id='TM4f2'><q id='TM4f2'></q></dir></style></legend>

                      <small id='TM4f2'></small><noframes id='TM4f2'>

                    1. <i id='TM4f2'><tr id='TM4f2'><dt id='TM4f2'><q id='TM4f2'><span id='TM4f2'><b id='TM4f2'><form id='TM4f2'><ins id='TM4f2'></ins><ul id='TM4f2'></ul><sub id='TM4f2'></sub></form><legend id='TM4f2'></legend><bdo id='TM4f2'><pre id='TM4f2'><center id='TM4f2'></center></pre></bdo></b><th id='TM4f2'></th></span></q></dt></tr></i><div id='TM4f2'><tfoot id='TM4f2'></tfoot><dl id='TM4f2'><fieldset id='TM4f2'></fieldset></dl></div>
                        <bdo id='TM4f2'></bdo><ul id='TM4f2'></ul>