java - 比较原始类型

我被问到

Given the definitions of a, b and c below, select the expressions that compile successfully and evaluate to true.

int a = 1;
char b = 'a';
boolean c = false;


所以我用一个简单的
if (expression)
{System.out.println("True");}
else
{System.out.println("False");}

这是正确的吗?
c==a         //false
!c || a      //false
b >= a       //true
c = a        //false
a - b - 96   //false
a + b > 0    //true
c = true     //true
a < b        //true

这样看起来还好吗?

最佳答案

  • c==a:不编译,不能将intboolean进行比较。
  • !c || a:不编译,不允许boolean || int
  • b >= a:编译,评估为true
  • c = a:无法编译,无法将int值分配给boolean
  • a - b - 96:编译,评估为-192
  • a + b > 0:编译,评估为true
  • c = true:编译,评估为true(并将true分配给c)
  • a < b:编译,评估为true
  • https://stackoverflow.com/questions/7914673/

    相关文章:

    compilation - apt-pkg编译问题

    objective-c - UIAlertView dismissWithClickedButton

    java - 编译时出现一个或多个错误的NetBeans项目

    php - 使用PHP的exec()函数(或类似函数),如何显示终端错误输出?

    compiler-construction - lex 使用来自 lex.yy.c 文件的 flex

    compiler-errors - nant 构建文件使用 nant 0.86 而不是 0.91 a

    c++ - 新手Chrome插件开发人员需要NPAPI入门方面的帮助

    objective-c - 尽管导入了正确的 header ,但使用自定义类的编译器错误

    java - Java编译时错误: reached end of file while parsin

    android - 在 Android 中初始化一个大的常量数据结构