单选题public void test(int x) {  int odd = x%2;  if (odd) {   System.out.println(“odd);  } else {  System.out.println(“even”);  }  }  Which statement is true?()A Compilation fails.B“odd” will always be output.C“even” will always be output.D“odd” will be outp

题目
单选题
public void test(int x) {  int odd = x%2;  if (odd) {   System.out.println(“odd);  } else {  System.out.println(“even”);  }  }  Which statement is true?()
A

Compilation fails.

B

 “odd” will always be output.

C

 “even” will always be output.

D

 “odd” will be output for odd values of x, and “even” for even values.

E

 “even” will be output for add values of x, and “odd” for even values.


相似考题
更多“单选题public void test(int x) {  int odd = x%2;  if (odd) {   System.out.println(“odd);  } else {  System.out.println(“even”);  }  }  Which statement is true?()A Compilation fails.B  “odd” will always be output.C  “even” will always be output.D  “odd” will b”相关问题
  • 第1题:

    下面程序段的输出结果是( )。 public class Test{ public static void main(String args[]){ int X,y; x=(int)Math.sqrt(5)/2+(int)Math.random*5/2; y=(int)Math.sqrt(3)/2+(int)Math.random*3/2; if(x>v) System.OUt.println("x>y"); elseif(x= =y) System.out.println("x=Y"); else System.out.println("x<y"): } }

    A.x>y

    B.x=Y

    C.x<y

    D.编译错误


    正确答案:A
    A。【解析】本题考查Java语言中if-else分支结构和几个标准函数语句的用法。本题中赋值号右边的两个表达式分别求两个标准函数的值,再进行整除,判断出x与y的大小。Math.sqrt计算一个数的平方根,Math.random输出[0,1)之间的随机数,本题中经过两条赋值语句后,x=1,y=0。进入分支结构后,满足if条件执行相应System.out.println("x>y");操作。

  • 第2题:

    下面程序段的输出结果是 public class Test{ public static void main(Stringargs[]){ int x,y; x=(int)Math.sqrt(5)/2+(int)Math.random()*5/2; y=(int)Math.sqrt(3)/2+(ht)Math.random()*3/2; if(x>y) System.out.println(”x>y”); else if(x=y) System.out.println(”x=y”); else System.out.Println(”x<y”); } }

    A.x>y

    B.x=y

    C.x<y

    D.编译错误


    正确答案:A
    解析:本题考查Java语言中if-else分支结构和几个标准函数语句的用法。Java语言的控制结构是考试重点,考生应该多读相关程序。这里重点理解程序中的两个赋值语句,赋值号右边的两个表达式分别求两个标准函数的值,再进行整除,判断出x与y的大小。Math.sqrt计算一个数的平方根,Math.random()输出[0,1)之间的随机数,本题中经过两条赋值语句后,x=1,y=O。进入分支结构后,满足if条件执行相应System.out.println(”x>y”);操作。

  • 第3题:

    设有如下程序: public class Sun { public static void main (String args[ ]) { int x,y; x= (int) Math.sqrt (2) /2+ (int) Math.random ()*2/2; y= (int) Math.sqrt (3) /3+ (int) Math.random ()*3/3; if (x>y) System.out.println ("x>y"); else if (x==y) System.out.println("x=y"); else System.out.println("x<y"); } } 程序运行的结果为( )。

    A.x>y

    B.x=y

    C.x<y

    D.以上都不对


    正确答案:B
    解析:本题是考查对if-else分支结构和几个标准函数语句的理解。程序第2、第3行赋值号右边的两个表达式分别求两个标准函数的值,再进行整除,根据我们对标准函数的理解,其中每项的值均为0,于是,两个表达式的值均为o,分别赋值给变量x和y,很容易判断出x是等于y的。进入分支结构后,if语句的条件x>y不满足,转去执行else if语句,条件x=y满足,执行System.out.println("x=y"),输出x=y。故本题答案是B。

  • 第4题:

    下面程序段的输出结果是______。 public class Test{ public static void main(String args[ ]){ int x,y; x=(int)Math.sqrt(5/2)+(int)Math.random( )*5/2; y=(int)Math.sqrt(3/2)+(int)Math.random( )*3/2; if(x>y) System.out.println("x>y"); else if(x==y) System.out.println("x=y"); else System.out.println("x<y"); } }

    A.x>y

    B.x=y

    C.x<y

    D.编译错误


    正确答案:A
    解析: 本程序中两个赋值语句右边的表达式分别求两个标准函数的值,再进行整除,判断 x和y的大小。Math.sqrt( )方法计算一个数的平方根,Math.random( )方法输出[1,0]之间的随机数,本题中经过两条赋值语句,x=1,y=0。进入分支结构后,满足if条件执行相应的System.out.println("x>y")操作。所以输出结果应该是选项A。

  • 第5题:

    What is odd is that they have perhaps most benefited from ambition — if not always their own then that of their parents and grandparents.


    正确答案:
    66. 【译文】奇怪的是他们也许已经从雄心壮志中获益颇多了——如果不是他们自己的雄心,那么就是他们父母的或祖父母的。
    【解析】此句主语为 what引导的主语从句,谓语为 have benefited from,宾语ambition,破折号后 if 引导让步状语从句。此处破折号后的状语从句为补充说明,位置不变为宜。
    重点词:ambition雄心壮志

  • 第6题:

    package test1;  public class Test1 {  static int x = 42;  }  package test2;  public class Test2 extends test1.Test1 {  public static void main(String[] args) { System.out.println(“x = “ + x);  }  }  What is the result?() 

    • A、 x = 0
    • B、 x = 42
    • C、 Compilation fails because of an error in line 2 of class Test2.
    • D、 Compilation fails because of an error in line 3 of class Test1.
    • E、 Compilation fails because of an error in line 4 of class Test2.

    正确答案:C

  • 第7题:

    public class Test {  public static void main(String[] args) {  int x = 0;  assert (x > 0) ? “assertion failed” : “assertion passed”;  System.out.println(“Finished”);  }  }  What is the result?()  

    • A、 finished
    • B、 Compilation fails.
    • C、 An AssertionError is thrown and finished is output.
    • D、 An AssertionError is thrown with the message “assertion failed”.
    • E、 An AssertionError is thrown with the message “assertion passed”.

    正确答案:B

  • 第8题:

    单选题
    a and b are positive, a is even and b is odd. Which of the following must also be odd?
    A

    ab

    B

    a/b

    C

    a + 2b

    D

    ba

    E

    (ab) a


    正确答案: D
    解析:
    An odd number raised to an even power equals an odd number. Take 32 = 9, for example, ba is the correct answer.

  • 第9题:

    问答题
    If w+x+y=42, what is the value of wxy?  (1) x and y are consecutive odd integers  (2) w=2x

    正确答案: C
    解析:
    将两个条件综合可知,wxy=2178,故本题选C项。

  • 第10题:

    单选题
    Lifeboats are numbered().Odd numbers to starboard and even numbers to port.
    A

    from forward to aft

    B

    from aft to forward

    C

    at master's option

    D

    as per owner's instruction


    正确答案: D
    解析: 暂无解析

  • 第11题:

    单选题
    public void test(int x) {  int odd = x%2;  if (odd) {   System.out.println(“odd);  } else {  System.out.println(“even”);  }  }  Which statement is true?()
    A

    Compilation fails.

    B

     “odd” will always be output.

    C

     “even” will always be output.

    D

     “odd” will be output for odd values of x, and “even” for even values.

    E

     “even” will be output for add values of x, and “odd” for even values.


    正确答案: C
    解析: 暂无解析

  • 第12题:

    问答题
    4 9 6 2 3 4 7 8 2 1 9 6 4 3 2  Multiply by 7 the number of odd numbers which are immediately followed by an even number in the list above. What is the answer?

    正确答案: 35
    解析: 紧跟在偶数后面的奇数有5个,分别是9、3、7、9、3。故5乘以7得35。odd number奇数。even number偶数。

  • 第13题:

    publicvoidtest(intx){intodd=x%2;if(odd){System.out.println(odd);}else{System.out.println(even”);}}Whichstatementistrue?()

    A.Compilationfails.

    B.“odd”willalwaysbeoutput.

    C.“even”willalwaysbeoutput.

    D.“odd”willbeoutputforoddvaluesofx,and“even”forevenvalues.

    E.“even”willbeoutputforaddvaluesofx,and“odd”forevenvalues.


    参考答案:A

  • 第14题:

    请编制函数ReadDa(()实现从文件IN83.DAT中读取1000个十进制整数到数组xx中。请编制函数 Compute()分别计算出xx中奇数的个数odd、奇数的平均值avel、偶数的平均值ave2及所有奇数的方差totfc的值。最后调用函数WrireDat()把结果输出到OUT83.DAT文件中。

    计算方差的公式如下:

    设N为奇数的个数,xx[i]为奇数,ave1为奇数的平均值。

    原始数据的存放格式是:每行存放10个数,并用逗号隔开(每个数均大于0且小于等于2000)。

    注意:部分源程序已给出。

    请勿改动主函数main()和输写函数WriteDat()的内容。

    试题程序:

    include<stdio.h>

    include<stdlib.h>

    include<string.h>

    define MAX 1000

    int xx[MAX],odd=0,even=0;

    double avel=0.0,ave2=0.0,totfc=0.0;

    void WriteDat(void);

    int ReadDat (void)

    {

    FILE *fp;

    if ( (fp=fopen ("IN83. DAT", "r") ) ==NULL) return 1;

    fclose (fp);

    return 0;

    }

    void Compute (void)

    {

    void main( )

    {

    int i;

    for (i=0; i<MAX; i++)

    xx[i]=0;

    if (ReadDat ())

    {

    printf ("数据文件IN83.DAT 不能打开!\007\n");

    return;

    }

    Compute ();

    printf ( "ODD=%d\nAVEl=%f\nAVE2=%f\nTOTFC=%f\n",odd,avel,ave2,totfc);

    WriteDat ();

    void WriteDat(void)

    {

    FILE *fp;

    int i;

    fp=fopen ("OUT83. DAT", "w");

    fprintf (fp,"%d\n%lf\n%lf\n%lf\n",odd,avel,ave2,totfc);

    fclose(fp);

    }


    正确答案:int ReadDat(void) { FILE *fp; int ij; if((fp=fopen("IN83.DAT""r"))==NULL) return 1; for(i=0;i100;i++) { for(j=0;j10;j++) fscanf(fp"%d"&xx[i*l0+j]); fscanf(fp"\n"); if(feof(fp)) break; } fclose(fp); return 0; } void Compute (void) { int iyy[MAX]; for(i=0;i1000;i++) if(xx[i]%2!=0) { odd++; /*计算出xx中奇数的个数odd*/ ave1+=xx[i]; /*求奇数的和*/ yy [odd-l] =xx [i]; /*将奇数存入组中yy中*/ } else { even++; /*计算出xx中偶数的个数even*/ ave2+=xx[i]; /*求偶数的和*/ } ave1/=odd; /*求奇数的平均值*/ ave2/=even; /*求偶数的平均值*/ for(i=0;iodd;i++) totfc+=(yy[i]-ave1)*(yy[i]-ave1)/odd; /*求所以奇数的方差*/ }
    int ReadDat(void) { FILE *fp; int i,j; if((fp=fopen("IN83.DAT","r"))==NULL) return 1; for(i=0;i100;i++) { for(j=0;j10;j++) fscanf(fp,"%d,",&xx[i*l0+j]); fscanf(fp,"\n"); if(feof(fp)) break; } fclose(fp); return 0; } void Compute (void) { int i,yy[MAX]; for(i=0;i1000;i++) if(xx[i]%2!=0) { odd++; /*计算出xx中奇数的个数odd*/ ave1+=xx[i]; /*求奇数的和*/ yy [odd-l] =xx [i]; /*将奇数存入组中yy中*/ } else { even++; /*计算出xx中偶数的个数even*/ ave2+=xx[i]; /*求偶数的和*/ } ave1/=odd; /*求奇数的平均值*/ ave2/=even; /*求偶数的平均值*/ for(i=0;iodd;i++) totfc+=(yy[i]-ave1)*(yy[i]-ave1)/odd; /*求所以奇数的方差*/ } 解析:本题考查的知识点如下:
    (1)从文件中读取数据。
    (2)奇偶数的判断和方差的求法。
    在C语言中,有一结构体类型FILE,其中包含文件的一些属性信息。可定义指针指向该结构体,这个指针称为文件指针。要从文件中读取数据,首先要判断该文件是否能以“读”的方式打开。若能打开,使用函数int fscanf(FILE*fp,char*format,args)从fp所指向的文件中依次读取数据。在本题中,数据的存放很有规律,将数据读出存入数组xx时,只要控制数组下标就可以了。若文件结束,则退出读取循环。最后要关闭文件。若一个数除以2取余得0,则该数是偶数,否则为奇数。由方差公式可知,这是求一些连续的数的表达式的值,所以可以使用循环求得方差。

  • 第15题:

    函数ReadDat()实现从文件IN.dat中读取1000个十进制整数到数组xx中;请编写函数 Compute()分别计算出数组xx中奇数的个数odd、偶数的个数even,以及所有数的平均值aver和方差totfc的值。最后调用函数WriteDat(),把结果输出到OUT. dat文件中。

    计算方差的公式如下:

    原始数据文件存放的格式是:每行存放10个数(每个数均大于0且小于等于2000),并用逗号隔开。

    注意:部分源程序已经给出。请勿改动主函数main()、读函数ReadDat()和输出数据函数 WriteDat()的内容。

    include <stdio. h>

    include <stdlib. h>

    include <string. h>

    define MAX 1000

    int xx[MAX], odd = 0, even = 0;

    double aver = 0.0, totfc = 0.0;

    void WriteDat(void);

    int ReadDat(void)

    { FILE *fp;

    int i, j;

    if ((fp = fopen("IN. dat", "r")) == NULL)

    return 1;

    for (i=0; i<100; i++)

    { for (j=0; j<10; j++)

    fscanf(fp, "%d,", &xx[i*10+j]);

    fscanf(fp, "\n");

    if (feof(fp))

    break;

    }

    fclose(fp);

    return 0;

    }

    void Compute(void)

    {

    }

    void main ()

    { int i;

    for (i=0; i<MAX; i++)

    xx[i] = 0;

    if (ReadDat())

    {

    printf (" 数据文件 IN. dar 不能打开! \007\n");

    return;

    }

    Compute ( );

    printf("odd=%d\neven=%d\naver=%f\ntotfc=%f\n", odd, even, aver, totfc);

    WriteDat ();

    }

    void WriteDat(void)

    { FILE *fp;

    fp = fopen("OUT.dat", "w");

    fprintf(fp, "%d\n%d\n%f\n%f\n", odd, even, aver, totfc);

    fclose (fp);

    }


    正确答案:void Compute (void) { int i; for (i=0; i1000; i++) { if (xx [i] %2) odd++; else even++; aver = aver+ xx[i]; } aver /= MAX; for (i=0; i1000; i++) totfc += (xx[i]-aver)*(xx[i]-aver)/MAX; } [解题思路] 对数组xx[i]中的1000个整数逐个进行扫描处理如果xx[i]对2的余数为 1则xx[i]为奇数变量odd加1;否则xx[i]为偶数变量even加1。把xx[i]的值与变量aver相加存入变量aver中。退出循环时变量aver的值除以MAX就得到平均值。最后在for循环语句中根据方差的公式求出所有数的方差。
    void Compute (void) { int i; for (i=0; i1000; i++) { if (xx [i] %2) odd++; else even++; aver = aver+ xx[i]; } aver /= MAX; for (i=0; i1000; i++) totfc += (xx[i]-aver)*(xx[i]-aver)/MAX; } [解题思路] 对数组xx[i]中的1000个整数逐个进行扫描处理,如果xx[i]对2的余数为 1,则xx[i]为奇数,变量odd加1;否则xx[i]为偶数,变量even加1。把xx[i]的值与变量aver相加存入变量aver中。退出循环时,变量aver的值除以MAX就得到平均值。最后在for循环语句中根据方差的公式求出所有数的方差。

  • 第16题:

    请编制函数ReadDat()实现从文件IN93.DAT中读取1000个十进制整数到数组xx中。请编制函数 Compute()分别计算出xx中奇数的个数odd、偶数的个数even、平均值aver及方差totfc的值,最后调用函数WriteDat()把结果输出到OUT93.DAT文件中。

    计算方差的公式如下:

    原始数据的存放格式是:每行存放10个数,并用逗号隔开(每个数均大于0且小于等于2000)。

    注意:部分源程序已给出。

    请勿改动主函数main()和写函数WriteDat()的内容。

    试题程序:

    include<stdio.h>

    include<stdlib.h>

    include<string.h>

    define MAX 1000

    int xx[MAX],odd=0,even=0;

    double aver=0.0,totfc=0.0;

    void WriteDat(void);

    int ReadDat(void)

    {

    FILE *fp;

    if((fp=fopen("IN93.DAT","r"))==NULL

    return 1;

    fclose(fp);

    return O;

    }

    void Compute(void)

    {

    }

    void main( )

    {

    int i;

    for(i=O;i<MAX;i++)

    xx[i] =0;

    if (ReadDat ( ) )

    {

    print f ("数据文件IN93.DAT不能打开! \007\n");

    return;

    }

    Compute();

    printf( "ODD=%d\nEVEN=%d\nAVER=%lf\nTOTFC=%lf\n",

    odd, even,aver,totfc);

    WriteDat();

    }

    void WriteDat(void)

    {

    FILE *fp;

    int i;

    fp=fopen("OUT93.DAT","w");

    fprintf(fp,"%dln%dln%lf\n%lfkn",odd,even,aver,totfc);

    fclose(fp);

    }


    正确答案:int ReadDat(void) { FILE *fp; int ij; if((fP=fopen("IN93.DAT""r"))==NULL) return 1; for(i=0;i100;i++) { for(j=0;j10;j++) fscanf(fp"%d"&xx[i*10+j]); fscanf(fp"\n"); if(feof(fp)) break; } fclose(fp); return 0; } void Compute(void) { int iyy[MAX]; for (i=0;i1000;i++) { if (xx[i]%2 !=0) odd+ +; /*求出xx中奇数的个数odd*/ else even++; /*求出xx中偶数的个数even*/ aver+=xx [i]; /*求出xx中元素的总和*/ } aver/=MAX; /*求出xx中元素的平均值*/ for (i=0; i1000; i++) totfc+=(xx[i]-aver)*(xx[i]-aver)/MAX; }
    int ReadDat(void) { FILE *fp; int i,j; if((fP=fopen("IN93.DAT","r"))==NULL) return 1; for(i=0;i100;i++) { for(j=0;j10;j++) fscanf(fp,"%d,",&xx[i*10+j]); fscanf(fp,"\n"); if(feof(fp)) break; } fclose(fp); return 0; } void Compute(void) { int i,yy[MAX]; for (i=0;i1000;i++) { if (xx[i]%2 !=0) odd+ +; /*求出xx中奇数的个数odd*/ else even++; /*求出xx中偶数的个数even*/ aver+=xx [i]; /*求出xx中元素的总和*/ } aver/=MAX; /*求出xx中元素的平均值*/ for (i=0; i1000; i++) totfc+=(xx[i]-aver)*(xx[i]-aver)/MAX; } 解析:本题考查的知识点如下:
    (1)从文件中读取数据。
    (2)奇偶数的判断和方差的求法。
    在C语言中,有一结构体类型FILE,其中包含文件的一些属性信息。可定义指针指向该结构体,这个指针称为文件指针。要从文件中读取数据,首先要判断该文件是否能以“读”的方式打开。若能打开,使用函数intfscanf(FILE*fp,char*format,args)从fp所指向的文件中依次读取数据。在本题中,数据的存放很有规律,将数据读出存入数组xx时,只要控制数组下标就可以了。若文件结束,则退出读取循环。最后要关闭文件。若一个数除以2取余得0,则该数是偶数,否则为奇数。由方差公式可知,这是求一些连续的数的表达式的值,所以可以使用循环求得方差。

  • 第17题:

    public void test(int x) {  int odd = x%2;  if (odd) {   System.out.println(“odd);  } else {  System.out.println(“even”);  }  }  Which statement is true?() 

    • A、Compilation fails.
    • B、 “odd” will always be output.
    • C、 “even” will always be output.
    • D、 “odd” will be output for odd values of x, and “even” for even values.
    • E、 “even” will be output for add values of x, and “odd” for even values.

    正确答案:A

  • 第18题:

    有一个表格,如果匹配所有行数为偶数的,用even实现,奇数的用odd实现。()


    正确答案:正确

  • 第19题:

    单选题
    If a and b are integers and the sum of ab and b is even, which of the following could be true?Ⅰ. a and b are both odd.Ⅱ. a is even and b is odd.Ⅲ. a is odd and b is even.
    A

    Ⅰ only

    B

    Ⅱonly

    C

    Ⅲ only

    D

    Ⅰ and Ⅱ

    E

    Ⅰand Ⅲ


    正确答案: C
    解析:
    Plug-in. StatementⅠ:if a and b are both odd, says a=1 and b=3, then ab+b=6. Since the sum is even, statementⅠ is true. StatementⅡ:1et a=2 and b=3, then ab+b=9. Since the sum is odd, this statement is false. Statement Ⅲ:let a=3 and b=2, then ab+b=8, which is even. So both statement Ⅰand statementⅢ are true.

  • 第20题:

    单选题
    Set X = even integers and Set Y = odd integers. Therefore X ∩ Y = ______.
    A

    prime numbers

    B

    integers

    C

    empty set

    D

    composite numbers

    E

    whole numbers


    正确答案: A
    解析:
    When two sets have nothing in common, we refer to their intersection as the empty set. There are two appropriate ways to denote the empty set: X∩Y={ } or X∩Y=φ.

  • 第21题:

    单选题
    When a buoy marks a channel bifurcation,the preferred channel is NOT indicated by().
    A

    the shape of an unlighted buoy

    B

    the light color of a lighted buoy

    C

    the color of the topmost band

    D

    whether the number is odd or even


    正确答案: B
    解析: 暂无解析

  • 第22题:

    单选题
    If m and n are positive integers and 3m+n-1=2m+2n, which of the following must be true?I. m and n are consecutive integers.II. m is even.III. n is odd.
    A

    None

    B

    I only

    C

    II only

    D

    III only

    E

    I, II, and III


    正确答案: D
    解析:
    Since m=n+1, where m and n are given as positive integers, Roman numeral choice I is true. Since, m=n+1, m can be either odd or even, hence choice II is false. Roman numeral choice III is also false since n can be either even or odd.

  • 第23题:

    单选题
    public class Test {  public static void main(String[] args) {  int x = 0;  assert (x > 0) ? “assertion failed” : “assertion passed”;  System.out.println(“Finished”);  }  }  What is the result?()
    A

     finished

    B

     Compilation fails.

    C

     An AssertionError is thrown and finished is output.

    D

     An AssertionError is thrown with the message “assertion failed”.

    E

     An AssertionError is thrown with the message “assertion passed”.


    正确答案: E
    解析: 暂无解析

  • 第24题:

    单选题
    x, y, and z are positive integers. Which of the following lists all the possible ways for x + y + z to be an odd number?I. One of the numbers is odd.II. Two of the numbers are odd.III. Three of the numbers are odd.
    A

    I

    B

    I and II

    C

    I and III

    D

    II and III


    正确答案: C
    解析:
    I. One of the numbers is odd. Let x be odd. Let y and z be even. y + z is even. An even plus an odd is odd, so x + y + z is odd.