ASCII和和元音检测 [英] ASCII sum and vowel detection

查看:71
本文介绍了ASCII和和元音检测的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到了为A = 65,B = 66等实现ASCII的问题。我使用ASCII的其他代码使用随机方法,当我实现它只打印一些随机字母。很抱歉,如果这似乎只是试图让我的硬件完成而不尝试,那不仅仅是我会如何在while循环中执行ASCII值。



我尝试过:



I'm having issues with implementing the ASCII for things like A = 65, B = 66 and so on. My other code that uses the ASCII uses the random method and when I implement that it just prints some random letters. Sorry if this seems like I'm just trying to get my HW done without trying, thats not it just stuck with how I would do the ASCII values within a while loop.

What I have tried:

public static void main(String[] args) 
    {
       Scanner in = new Scanner(System.in);
        System.out.print("Input some text: ");
        String str = in.nextLine();
        
       int chr = 'A';
       int chr2 = 'E';
       int chr3 = 'I';
       int chr4 = 'O';
       int chr5 = 'U';
       boolean vowel = false;
       
       while(vowel)
       {
           if(chr == 'A' && chr2 == 'E' && chr3 == 'I' && chr4 == 'O' && chr5 == 'U')
           {
              System.out.println("A vowel was entered");
           }else
           {
               System.out.println("A vowel was not entered");
           }
       }
    }
}

推荐答案

嗯,你很远由于一系列原因,远远没有解决方案:

Well, you're far, far of solution due to set of reasons:


  1. 元音集取决于语言(例如一组波兰元音是:{A ,Ą,E,Ę,....,O,Óa,ą,e,ę,... o,ó}等,
  2. 元音可能是大写或小写。所以,你必须定义它:


  1. A vowel set depends on language (for example a set of polish vowels is: {A, Ą, E, Ę, ...., O, Ó a, ą, e, ę, ... o, ó} etc.,
  2. A vowel may be upper or lower case. So, you have to define it:
String vowels = "aeiouAEIOU";

  • 您的,而循环什么都不做,我的意思是不要在输入的文本中搜索元音。
  • your while loop does nothing, i mean that do not searches vowels in entered text.




  • 这是一个如何编写元音检测的想法程序: java - 如何检测元音和辅音我的程序 - Stack Overflow [ ^ ]



    我强烈建议从基础开始:

    Java™教程 [ ^ ]

    跟踪:学习Java语言(The Java™Tutorials) [ ^ ]



    Here is an idea how to write a vowel detection programme: java - How to Detect the Vowels and Consonants in my program - Stack Overflow[^]

    I'd strongly recommend to starts from basics:
    The Java™ Tutorials[^]
    Trail: Learning the Java Language (The Java™ Tutorials)[^]


    这篇关于ASCII和和元音检测的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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