小编use*_*3gg的帖子

什么是'?' 在代码中

谁能解释这些代码?为什么它?在那里?

package course.examples.theanswer;

import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;

public class TheAnswer extends Activity {

public static final int[] answers = { 42, -10, 0, 100, 1000 };
public static final int answer = 42;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.answer_layout);

    TextView answerView = (TextView) findViewById(R.id.answer_view);


    int val = findAnswer();
    String output = (val == answer) ? "42" : "We may never know";
    answerView.setText("The answer to life, the universe and everything is:\n\n"
                    + output);
}

private …
Run Code Online (Sandbox Code Playgroud)

java android ternary-operator

-3
推荐指数
1
解决办法
165
查看次数

标签 统计

android ×1

java ×1

ternary-operator ×1