以下程序的输出结果是()。enumColor{Red,Green=2,Blue}staticvoidMain(strin

题目
单选题
以下程序的输出结果是()。enumColor{Red,Green=2,Blue}staticvoidMain(string[]args){Colorc=0;Colorc1=(Color)2;Console.WriteLine("{0},{1}",c,c1);Console.Read();}
A

Green,Red

B

Red,Green

C

Red,Blue

D

Green,Blue

参考答案和解析
正确答案: C
解析: 暂无解析
如果没有搜索结果或未解决您的问题,请直接 联系老师 获取答案。
相似问题和答案

第1题:

在下列程序段中,enumcolor{red,yellow,blue=4,green,white}c1,c2;c1=yellow;c2=white;枚举变量c2的值是()

A、1

B、3

C、5

D、6


参考答案:D

第2题:

阅读以下说明和Java代码,将应填入(n)处的语句写在对应栏内。

【说明】

本程序通过移动滑动条修改颜色RGB值,从而控制颜色。程序中有一个面板、3个标签和3个滑动条,标签和滑动条一一对应,分别对应三原色红、绿、蓝,任意拖动其中的一个滑动条,所对应的颜色值就会发生变化,面板的颜色也会发生对应的变化,如下图所示,滑动条值的范围是0~255。

【Java代码】

import java.awt.*;

import java.awt.event.*;

import javax.swing.*;

public class simple extends JFrame. implements AdjustmentListener{

public simple(){

setTitle("simple");

setSize(300, 200);

addWindowListener(new WindowAdapter(){

public void windowClosing((1)){

System.exit(0);

}

});

Container contentPane=getContentPane();

JPanel p=(2);

p.setLayout(new GridLayout(3, 2));

p.add(redLabel=new JLabel("Red 0"));

p.add(red=new JScrollBar(Adjustable. HORIZONTAL, 0, 0, 0, 255));

red.setBlocklncrement(16);

red.addAdjustmentListener(this);

p.add(greenLabel=(3) ("Green 0"));

p.add(green=new JScrollBar(Adjustable.HORIZONTAL 0, 0, 0, 255));

green setBIocklncrement(16);

green.addAdjustmentListener(this);

p.add(blueLabel=new JLabel("Blue 0"));

p.add(btue=new JScrollBar(Adjustable. HORIZONTAL, 0, 0, 0, 255));

blue,setBIocklncrement(16);

blue.addAdjustmentListener(this);

contentPane.add(p, "South");

colorPanet=new JPanel();

colorPanet.setBackground(new Color(0, 0, 0));

contentPane.add((4),"Center");

} public void adjustmentValueChanged(AdjustmentEvent evt){

redLabel.setText("Red"+red.getValue());

greenLabel.setText("Green"+green.getValue());

blueLabel.setText("Blue"+blue.getValue());

coiorPanel.setBackground(new Color(red.getValue(), green.getValue(), blue.getValue()));

colorPanel.repaint();

}

public static void main(String[] args){

JFrame. f=(5);

f.show();

}

private JLabel redLabel;

private JLabel greenLabel;

private JLabel blueLabel;

private JScrollBar red;

private JScroilBar green;

private JScrollBar blue;

private JPanel colorPanel;


正确答案:(1)WindowEvent e (2)new JPanel() (3)new JLabel (4)colorPanel (5)new simple()
(1)WindowEvent e (2)new JPanel() (3)new JLabel (4)colorPanel (5)new simple() 解析:本题考查在Java中实现对面板颜色的控制。
题目要求三原色红、绿、蓝,通过任意拖动其对应的一个滑动条来改变,而面板的颜色也会发生对应的变化。这需要我们了解Java中对滑动条和颜色进行定义的类。下面我们来分析程序。
第(1)空在类simple的构造函数中,这个类是继承JFrame这个框架类的,这个构造函数的作用是创建一个框架。很明显此空是函数windowClosing()的参数,而这个函数的作用我们不难看出是关闭框架用的,其参数是WindowEvent e,因此,此空答案就为 WindowEvent e。
第(2)空是给JPanel类型的变量p赋一个值,JPanel类型是控制板类型,在程序上面申请了一个容器,此空应该是在容器中创建一个控制板,而Java中一般用关键字new来创建对象,因此,此空答案为new JPanel()。
第(3)空是给变量greenLabel赋一个初值,从程序中我们不难看出greenLabel是一个标签类型的变量,且其中存放的是绿色的值。结合程序中上下红和蓝的处理我们也不难推断出此空的答案为new JLabel。
第(4)空是容器对象contentPane的add()函数的参数,这个函数的作用是往其对象中增加内容,其第一个参数是要添加的对象,第二个参数是添加的位置,从程序中不难看出应该添加对象colorPanel,这是界面中下面的板块。因此,此空答案为colorPanel。
第(5)空是给JFrame类型的变量f赋一个值,而JFrame是框架类simple的父类,那么变量f应该是一个框架对象,关键字new一般用来创建一个新的对象,因此,此空答案为new simple()。

第3题:

设有说明var color:(red,green,yellow,blue);a:boolean;下面语句正确的是( )。

Aolor:=‘green‘;

Bwriteln(green);

Cwriteln(color);

Da:=color=red;


正确答案:D

第4题:

以下程序的输出结果是 【 11 】。

#include <stdio.h>

main( )

{ char *ch[4]={"red',"green","blue"};

int i=0;

while( ch[i] )

{ putchar( ch[i][0]); i++;)

}


正确答案:
【答案】rgb
【知识点】指针数组的使用方法
【解析】本函数功能是打印二维数组中每一行的第一个字符的值。

第5题:

以下选项中不能正确把cl定义成结构体变量的是

A.typedef struct { int red; int green; int blue; } COLOR; COLOR cl;

B.struct color cl { int red; int green; int blue; }

C.struct color { int red; int green; int blue; } cl;

D.struct { int red; int green; int blue; } cl;


正确答案:B
解析:选项A)是把结构体类型改名后定义为变量cl。选项C),D)则是在定义结构体类型时定义变量,而选项B)不符合结构体类型定义的语法规则。

第6题:

以下选项中不能正确把c1定义成结构体变量的是

A.typedef struct {int red: int green: int blue; } COLOR; COLOR c1;

B.struct color c1 {int red int green: int blue; };

C.struct color {int red , int green : int blue : )cl;

D.struct {int red; int green; int blue } c1 ;


正确答案:B
解析:本题考核的知识点是结构体类型定义。结构体类型的定义格式为:strcut结构体名{成虽说明列表};结构体变量的定义有3种形式:第一种,定义结构体型的同时定义结构体变量,如:strcut结构体名{成员说明列表}变量;选项C属于这种情况,故选项C正确:第二种,先定义一个结构体类型,然后使用该类型来定义结构体变量,如:strcutstudent{成员说明列表}:student变量;选项A属于这种情况,故选项A正确;第三种,定义一个无名称的结构体类型的同时定义结构体变量,如:strcutstudent{成员说明列表}变量;选项D属于这种情况,故选项D正确.所以,4个选项中选项B符合题意。

第7题:

publicclassBall{publicenumColor{RED,GREEN,BLUE};publicvoidfoo(){//insertcodehere{System.out.println(c);}}}Whichcodeinsertedatline14causesthefoomethodtoprintRED,GREEN,andBLUE?()

A.for(Colorc:Color.values())

B.for(Colorc=RED;c<=BLUE;c++)

C.for(Colorc;c.hasNext();c.next())

D.for(Colorc=Color[0];c<=Color[2];c++)

E.for(Colorc=Color.RED;c<=Color.BLUE;c++)


参考答案:A

第8题:

在下列程序段中,enumcolor{red,yellow,blue,green,white}c1;c1=white;枚举变量c1的值是()

A、1

B、4

C、5

D、6


参考答案:B

第9题:

以下选项中不能正确把c1定义成结构体变量的是

A.typedef struct { int red; int green;; int blue; }COLOR; COLOR cl;

B.struct color cl { int red; int green; int blue; };

C.struet color { int red; int green; int blue; }c1;

D.struct { int red; int green; int blue; }cl;


正确答案:B
解析:结构体类型的定义格式为:
  stract结构体名
  成员说明列表};
  结构体变量的定义有3种形式:第一种,定义结构体类型的同时定义结构体变量,如: street结构体名{成员说明列表}变量;第二种,先定义一个结构体类型,然后使用该类型来定义结构体变量,如:strect student{成员说明列表};student变量;第三种,定义一个无名称的结构体类型的同时定义结构体变量,如:strect student{成员说明列表}变量;。

第10题:

下列选项中不能正确定义结构体的是_______。

A.typedef struct

B.struct color cl {int red; {int red; int green; int green; int blue; int blue; }COLOR; }; COLOR cl;

C.struct color

D.struct {int red; {int red; int green; int green; int blue; int blue; }cl; }cl;


正确答案:B
解析:将一个变量定义为标准类型与定义为结构体类型不同之处在于:后者不仅要求指定变量为结构体类型,而且要求指定为某一特定的结构体类型(例如,struct color),不能只指定结构体名。其中可以不出现结构体名,答案D就是缺省结构体名的隋况。而变量名歹婊必须放在成员列表后面,所以B答案不能正确将cl定义为结构件变量。

更多相关问题