【问题标题】:How do I make a case where a char variable is an apostrophe?如何判断 char 变量是撇号的情况?
【发布时间】:2015-11-28 20:29:08
【问题描述】:

所以这可能是一个愚蠢的问题,但我使用如下 switch 语句:

switch (letter) {
case 'a': return 0;
case 'b': return 1;
case 'c': return 2;
case 'd': return 3;
case 'e': return 4;
case 'f': return 5;

...等

我正在尝试使用字母是撇号的​​情况。我该如何格式化?我是否使用双引号: " ' " ?或单引号:'''?

【问题讨论】:

    标签: switch-statement quotes


    【解决方案1】:

    您可以使用它的十进制 ASCII 值 - 撇号值为 39。 所以,试试吧

    case 39:
    

    【讨论】:

      【解决方案2】:

      你需要

      case '\'':
      

      使用这样的反斜杠称为转义序列。

      https://docs.oracle.com/javase/tutorial/java/data/characters.html

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2011-12-11
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2012-07-11
        • 2022-01-20
        相关资源
        最近更新 更多