niusouti.com

给定如下Java代码片段,编译运行时,结果是() int [ ] a = {1,2,3,4,5}; for (int count = 0 ; count<5; count++) System.out.print(a[count++]) ;A.运行时出现异常B.输出:12345C.输出:135D.输出:24

题目

给定如下Java代码片段,编译运行时,结果是() int [ ] a = {1,2,3,4,5}; for (int count = 0 ; count<5; count++) System.out.print(a[count++]) ;

A.运行时出现异常

B.输出:12345

C.输出:135

D.输出:24


相似考题
参考答案和解析
输出:135
更多“给定如下Java代码片段,编译运行时,结果是() int [ ] a = {1,2,3,4,5}; for (int count = 0 ; count<5; count++) System.out.print(a[count++]) ;”相关问题
  • 第1题:

    下面程序的功能是统计用0至9之间的不同的数字组成的三位数的个数。main(){ int i,j,k,count=0;for(i=1;i<=9;i++)for(j=0;j<=9;j++)if(【】)continue;else for(k=0;k<=9;k++)if(【】)count++;printf("%d",count);}


    正确答案:i= =j
     k!=i&&k!=j
    因为题目的要求是用不同的数字进行组合,因此到这里首先要判断i和j是否一样。同理,到第三位数出现的时候,我们也要判断这三个数字是否相同。

  • 第2题:

    下面程序的运行结果是【】。 inChlde using namespace std; class count { static int n;

    下面程序的运行结果是【 】。

    inChlde<iOStream>

    using namespace std;

    class count

    {

    static int n;

    public:

    count()

    {

    n++;

    }

    static int test()

    {

    for(int i=0:i<4;i++)

    n++;

    return n;

    }

    };

    int count::n=0;

    int main()

    {

    cout<<COUnt::test()<<" ";

    count c1, c2;

    cout<<count::test()<<end1;

    return 0;

    }


    正确答案:4 10
    4 10 解析:本题主要考查C++类中静态数据成员的使用。题目程序首先定义了类count,其内部含有private类型数据成员static int n;同时含有public类型构造函数count()和静态成员函数static int test(),这两个函数的功能分别是为对象申请系统资源并将静态数据成员n加1和将静态数据成员n加4。主函数前,程序将静态数据成员n初始化为0,该数据成员为所有类count的对象所共有的数据成员:主函数中程序首先执行静态成员函数test()(由于test声明为static,因此其调用时无需通过具体对象),其执行过程中,静态数据成员n应该加4变成n=4,因此此处输出为4:此后程序创建对象c1和c2,由于在每次创建过程中都要调用构造函数count(),而每次调用 count()函数后,静态数据成员n值都会加1因此,创建两个对象之后,n值变为n= 6:再次执行test()函数后,n的值再次加4,因此变为n=6+4=10。故程序全部执行后,变量n值变为10,而中间程序输出为“410”。

  • 第3题:

    下面程序的正确输出是( )。 public class Hello { public static void main(String args[]) { int count, xPos=25; for ( count=1; count<=10; count++ ) { if ( count==5 ) break; System.out.println(count ); xPos += 10; } } }

    A.1 2 3 4

    B.1 3 4

    C.编译错误

    D.以上都不是


    正确答案:A
    解析:该程序经过编译、运行后,在屏幕上显示;1 2 3 4。public class Hello中Hello为类名,public static void main(String args[])有关参数的解释如下。public——表示该方法可以被任意代码所调用,包括Java解释器。 static——它告诉编译器,main()方法是一个类方法,可以通过类名直接调用,调用时不需要该类的实例对象。void——表示main()方法没有返回值。这是非常重要的。因为Java类型检查非常严格,包括检查这些方法返回值的类型是否与声明的一致。String args[]——声明一个字符串类型的数组。它是命令行传递给main()方法的参数,参数在命令行中出现在类名称后面。包含main()方法的类(Hello为包含main()方法的类名)名称必须与其文件名相同,也就是说,其文件名必须为Hello.java。经过编译,在当前文件夹下将出现一个Hello.class文件,这就是编译后的字节码文件。在程序段最后有两个大括号,分别说明结束main()方法和Hello类。在本程序中由于有count==5这个条件判断,因此当count==5时,程序结束,输出为1 2 3 4。

  • 第4题:

    下面C程序段中count++语句执行的次数为(64)。

    for(int i=1;i<=11;i*=2)

    for(int j=1;j<=i;j++)

    count++:

    A.15

    B.16

    C.31

    D.32


    正确答案:A
    解析:程序段中在第一层for循环内,每执行一次,count++就被执行i次,i从1每次翻倍直到8.所以,count++总共被执行的次数是:1+2+4+8=15次。

  • 第5题:

    下面的哪些程序段可以正确地获得从命令行传递的参数的个数?()

    A.int count = args.length;

    B.int count = args.length-1;

    C.int count=0; while(args[count]!=null) count++;

    D.int count=0;while (!(args[count].equals(“”))) count++;


    正确答案:A

  • 第6题:

    有如下程序: include using namespace std; class pumpkin{ public:pumpkin(){++count

    有如下程序:

    include<iostream>

    using namespace std;

    class pumpkin{

    public:

    pumpkin(){++count;}

    ~pumpkin(){--count;}

    static void total_count(){

    cout<<count<<"pumpkin(s)"<<end1;

    }

    private:

    static int count;

    };

    int pumpkin::count=0;

    int main(){

    pumpkin p1[10];

    pumpkin::total_count();

    return 0;

    }

    这个程序的输出结果是______。


    正确答案:10pumpkin(s)
    10pumpkin(s) 解析:此题考查的是静态数据成员。题目中count数据成员要定义成静态的,静态数据成员是类中所有对象共享的成员,而不是某个对象的成员。本题中,pumpkin类定义了一个静态数据成员count,并初始化为0。在主函数中,首先定义了该类对象p1[10],所以构造函数被调用10次,count累加1十次;然后调用函数total count(),通过函数该输出count的值10。total count()函数结束,对象被释放,故析构函数被调用了10次,count变成0。

  • 第7题:

    int Calc(unsigned int x)

    {

    int count=0;

    while(x)

    {

    printf("x=%i\n",x);

    count++;

    x=x&(x-1);

    }

    return count;

    }

    问 Calc(9999)的值是多少。


    正确答案:
     

  • 第8题:

    有如下程序:includeusing namespace std;class Toy{public:Toy(char*_n){strcpy(name

    有如下程序: #include<iostream> using namespace std; class Toy{ public: Toy(char*_n){strcpy(name,_n);count++;} ~Toy(){count--;} char*GetName( ){return name;} static int getCount( ){return count;} private: char name[10]; static int count; }; int Toy::count=0: int main( ){ Toy tl("Snoopy"),t2("Mickey"),t3("Barbie"); cout<<t1.getCount( )<<endl; return 0; } 程序的输出结果是

    A.1

    B.2

    C.3

    D.运行时出错


    正确答案:C
    解析:静态数据成员是同一个类的不同对象之间的数据共享,无论创建多少个类,均只有一个静态数据成员,通过对静态数据成员的调用,实现了数据共享。本题创建了3个Toy对象,所以调用3次构造函数,count被增加3次,故sount=3。

  • 第9题:

    程序段intcount=0;char*s=”ABCD”;while(*s!=’/0’){s++;count++;}执行后count=()。
    4

  • 第10题:

    int[]my_Array; my_Array=newint[5]; for(intcount=0;count<=5;count++)System.out.println(my_Array[count]); 以上Java代码运行的结果是()。

    • A、将1,2,3,4,5输出到屏幕
    • B、将0,1,2,3,4输出到屏幕
    • C、将0,1,2,3,4,5输出到屏幕
    • D、将出现运行时异常

    正确答案:D

  • 第11题:

    单选题
    For debugging purposes, you need to record how many times a given JSP is invoked before the user’ssession has been created. The JSP’s destroy method stores this information to a database. Which JSPcode snippet keeps track of this count for the lifetime of the JSP page?()
    A

    <%! int count = 0; %><% if ( request.getSession(false) == null ) count++; %>

    B

    <%@ int count = 0; %>. <% if ( request.getSession(false) == null ) count++; %>

    C

    <% int count = 0;. if ( request.getSession(false) == null ) count++; %>

    D

    <%@ int count = 0;. if ( request.getSession(false) == null ) count++; %>

    E

    <%! int count = 0;. if ( request.getSession(false) == null ) count++; %>


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

  • 第12题:

    单选题
    编译如下Java程序片断:  class test{  int count = 9;  public void a(){    int count=10;  System.out.println("count 1 =" + count);  }  public void count(){  System.out.println("count 2 =" + count);  }  public static void main(String args[]){    test t=new test();    t.a();   t.count();   } }  结果将()。
    A

    不能通过编译

    B

    输出:       count 1 = 10        count 2 = 9

    C

    输出:          count 1 = 9          count 2 = 9


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

  • 第13题:

    如下程序的输出结果是______。 include using namespace std; class pumpkin{ publ

    如下程序的输出结果是______。

    include<iostream>

    using namespace std;

    class pumpkin{

    public:

    pumpkin( ){++count;}

    ~pumpkin( ){--eount;}

    static void total_count( ){cout<<count<<"pumpkin(s)"<<endl;}

    private:

    static int count;

    };

    int pumpkin::count=0;

    int main( ){

    pumpkin pl[10];

    pumpkin::total_count( );

    return 0;

    }


    正确答案:10pumpkin(s)
    10pumpkin(s) 解析:在主函数中pumpkin pl[10];定义了一个有10个元素的对象数组,所以调用了10次构造函数,静态数据成员court累加了10次,pumpkin::total_count( );显式调用类成员函数,直接调用静态成员函数:total_count( ),打印pumpkin(s)。

  • 第14题:

    ( 27 )有如下程序:

    #include<iostream>

    using namespace std;

    class MyClass{

    public:

    MyClass(){++count;}

    ~MyClass(){--count;}

    static int getCount(){return count;}

    private:

    static int count;

    };

    int MyClass::count=0;

    int main(){

    MyClass obj;

    cout<<obj.getCount();

    MyClass*ptr=new MyClass;

    cout<<MyClass::getCount();

    delete ptr;

    cout<<MyClass::getCount();

    return 0;

    }

    程序的输出结果是

    A ) 121

    B ) 232

    C ) 221

    D ) 122


    正确答案:A

  • 第15题:

    ( 27 )有如下程序:

    #include <iostream>

    using namespace std;

    class Toy{

    public:

    Toy(char* _n) { strcpy (name,_n); count++;}

    ~Toy(){ count--; }

    char* GetName(){ return name; }

    static int getCount(){ return count; }

    private:

    char name[10];

    static int count;

    };

    int Toy::count=0;

    int mail(){

    Toy t1("Snoopy"),t2("Mickey"),t3("Barbie");

    cout<<t1.getCount()<<endl;

    return 0;

    }

    运行时的输出结果是

    A ) 1

    B ) 2

    C ) 3

    D )运行时出错


    正确答案:C

  • 第16题:

    从键盘上输入XXYYZZXYZWXP和X,以下程序的输出结果是【】。 include include

    从键盘上输入XXYYZZXYZWXP和X,以下程序的输出结果是【 】。

    include<iostream.h>

    include<string.h>

    void main(){

    char*str,ch;

    int count=0,pos;

    cin>>str>>ch;

    pos=strlen(str)-1;

    while(pos>=0){

    if((str[pos])=ch)count++;

    pos--;

    }

    cout<<"count="<<count;

    }


    正确答案:count=4
    count=4

  • 第17题:

    Fordebuggingpurposes,youneedtorecordhowmanytimesagivenJSPisinvokedbeforetheuser’ssessionhasbeencreated.TheJSP’sdestroymethodstoresthisinformationtoadatabase.WhichJSPcodesnippetkeepstrackofthiscountforthelifetimeoftheJSPpage?()

    A.<%!intcount=0;%><%if(request.getSession(false)==null)count++;%>

    B.<%@intcount=0;%>.<%if(request.getSession(false)==null)count++;%>

    C.<%intcount=0;.if(request.getSession(false)==null)count++;%>

    D.<%@intcount=0;.if(request.getSession(false)==null)count++;%>

    E.<%!intcount=0;.if(request.getSession(false)==null)count++;%>


    参考答案:A

  • 第18题:

    有如下程序:

    #include<iostream>

    using namespace std;

    class Toy{

    public:

    Toy(char*_n){strcpy(name,_n);count++;}

    ~Toy()}count--;}

    char*GetName(){return name;}

    static int getCount(){return count;}

    private:

    char name[10];

    static int count;

    };

    int Toy::count=O:

    int main(){

    Toy tl(“Snoopy”),t2(“Mickey”),t3(“Barbie”);

    cout<<t1.getCount()<<endl;

    return O:

    }

    运行时的输出结果是

    A.1

    B.2

    C.3

    D.运行时出错


    正确答案:C
    解析:count为Toy类的静态变量,每定义一个TOy类的对象即在构造函数中对count变量进行加1的操作。程序中一共定义了3个对象,所以count=3,故选C)。

  • 第19题:

    给定一个Java程序代码,如下:运行编译后,输出结果是()。

    A.count1=9count2=9

    B.count1=10count2=9

    C.count1=10count2=10

    D.count1=9count2=10


    正确答案:B

  • 第20题:

    ● 下面C程序段中count++语句执行的次数为 (64) 。

    for(int i = 1;i <= 11;i *= 2)

    for(int j = 1; j <= i;j++)

    count++;

    (64)

    A. 15

    B. 16

    C. 31

    D. 32


    正确答案:A

  • 第21题:

    int [] my_Array;  my_Array = new int[5];  for(int count = 0; count <= 5; count++)  System.out.println(my_Array[count]); 结果是()

    • A、将1,2,3,4,5输出到屏幕
    • B、将0,1,2,3,4输出到屏幕
    • C、将0,1,2,3,4,5输出到屏幕
    • D、将出现运行时异常

    正确答案:D

  • 第22题:

    编译如下Java程序片断:  class test{  int count = 9;  public void a(){    int count=10;  System.out.println("count 1 =" + count);  }  public void count(){  System.out.println("count 2 =" + count);  }  public static void main(String args[]){    test t=new test();    t.a();   t.count();   } }  结果将()。    

    • A、不能通过编译
    • B、输出:       count 1 = 10        count 2 = 9
    • C、输出:          count 1 = 9          count 2 = 9

    正确答案:B

  • 第23题:

    单选题
    int [] my_Array;   My_Array=new int [5];   For(int count = 0 ;  count <=5; count ++)    System.out.pringtln(my_Array[count]);   以上Java代码运行的结果是()
    A

    将1,2,3,4,5输出到屏幕

    B

    将0,1,2,3,4输出到屏幕

    C

    将0,1,2,3,4,5输出到屏幕

    D

    将出现运行时异常


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

  • 第24题:

    单选题
    编译如下的Java程序片段:  Class test{     Int count=9;     Public void a(){   Int count=10;   System.out,println(“count 1=” + count); }  Public void count(){   System.out.println(“count 2 =”+ count); }  Public static void main(String args[] ){   Test t=new Test();   t.a();   t.count(); } }  结果是()
    A

    不能通过编译

    B

    输出:count 1 =10  count 2=9

    C

    输出:count 1=9 count 2=9


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