0:00

The following method will return true if and only if:

public boolean check(String s) {
   return s.length() >= 2 && (s.charAt(0) ==
      s.charAt(1) || check(s.substring(1)));
}
使用递归方法检测字符串中是否有连续的相同字符。
3

Susan is five years older than Matt. Three years from now Susan’s age will be twice Matt’s age. What should be in place of the following condition to solve this problem?

for (int s = 1; s <=100; s++) {
   for (int m = 1; m <= 100; m++) {
      if (condition)
         System.out.println("Susan is " + s + " and Matt is " + m);
   }
}
三年后Matt的年龄是m + 3,其两倍是2 * m + 6。算数运算优先级高于比较运算,比较运算优先级高于逻辑运算,因而括号不是必须的。
4

Assuming that x and y have been declared as valid integer values, which of the following is equivalent to this statement?

(x > 15 && x < 18) || (x > 10 || y < 20)

逻辑或连接的条件彼此可以互换顺序,因为只要其中一个成立,整个表达式就成立。
3

What would the following print?

int x = 3;
int y = 2;
if (x > 2) x++;
if (y > 1) y++;
if (x > 2) System.out.print("first ");
if (y < 3) System.out.print("second ");
System.out.print("third");

执行到最后一个ify值为3,因而条件不成立。
4

What would the following print?

int x = 3;
int y = 2;
if (y / x > 0)
   System.out.print("first ");
   System.out.print("second ");
对于整数除法,y / x的值为0,故条件不成立。但是if只作用在紧随其后的第一个语句上。
2


陈 欣

AADPS创始人

发表评论