java习题

本文详细探讨了Java编程中的常见语法错误和陷阱,包括for循环的使用、变量初始化、数组操作、条件判断和循环控制。通过实例解析了如何避免这些错误,提升代码质量。同时,介绍了Java数据类型、字符串操作和方法调用的基本规则,帮助读者深入理解Java编程的核心概念。
摘要由CSDN通过智能技术生成

🔎:以下哪个 for 语句是错误的?

选项:A.for(i=0;j=0;i<10;i++)B.for(i=0,j=0;i<10;i++)C.for(i=0;i<10;i++)D.for(i=0;i<10;i++,j++)

💯:A

🔎:对于下面这段代码,以下说法正确的是:()。

选项:A.程序会打出 "Value is 0"B.程序会抛出 NullPointerExceptionC.非静态变量不能够被静态方法引用D.编译器会抛出 "possible reference before assignment"的错误

💯:C

🔎:中国大学MOOC: 对于以下代码段:String s1 = a;String s2 = b;String s3 = ;以下操作可以编译的是:

选项:

💯:s3 = s1 + s2;

🔎:以下哪个是定义和创建数组的正确方式

选项:

💯:int a[] = {1,2,3,4,5};

🔎:已知如下代码,执行结果是 ________ boolean m = true; if ( m = = false ) System.out.println(“False”); else System.out.println(“True”);

选项:A.FalseB.TrueC.NoneD.编译出错,不能运行

💯:B

🔎:中国大学MOOC: 以下代码片段之行后,temp的值是?int temp = (int)3.9;temp %= 2;

选项:

💯:1

🔎:循环语句 while (!x&&!y) 中的循环条件表达式等价于

选项:A.!(x!=0||y!=0)B.!(x0 && y0)C.!(x0 || y0)D.x=0 && y=0

💯:A

🔎:中国大学MOOC: 有以下代码片段:int m[] = {0, 1, 2, 3, 4, 5, 6 };以下哪项可以给出数组的单元个数?

选项:

💯:m.length

🔎:假设字符变量ch中存放有小写英文字母,将其转换为相应的大写英文字母的表达式是 ( )

选项:

💯:ch = ch-‘a’+‘A’

🔎:以下哪个是有效的Java程序入口函数?

选项:A.public static void main(String[] args);B.public static void main();C.public static int main(String[] args);D.public static void main(int argc, String[] args)

💯:A

🔎:中国大学MOOC: 对于String s;,以下哪句是对的?

选项:

💯:s是一个变量,它将要管理一个String的对象

🔎:中国大学MOOC: 以下代码片段: String s1 = hello; String s2 = hello; System.out.println(s1 == s2);以下哪句是正确的?

选项:

💯:输出“true”

🔎:有以下定义: double a,b,c;则以下哪个表达式与a/b/c不等价?

选项:A.a/(b/c)B.a/c/bC.a/(b*c)D.(a/b)/c

💯:A

🔎:以下哪句不能编译?

选项:

💯:if ( a==b ) else printf(“no”);

🔎:以下哪个循环并非重复5次?

选项:

💯:int i; for (i=0; i<=5; i++) {}

🔎:中国大学MOOC: 以下哪个循环能编译?

选项:

💯:for ( i=10 ; i++; ) {}

🔎:中国大学MOOC: 对于以下代码: int i=6; do { System.out.println(i–); } while (false); 哪句话是对的?

选项:

💯:打印出6

🔎:编译Java源程序文件将产生相应的字节码文件,这些字节码文件的扩展名为()

选项:A.byteB.classC.htmlD.exe

💯:B

🔎:public static int getValue(int i) { int result = 0; switch (i) { case 1: result = result + i; case 2: result = result + i * 2; case 3: result = result + i * 3; } return result; }

选项:A.0B.2C.4D.10

💯:D

🔎:Given the following code:     public class Person{ static int arr[] = new int[10];  public static void main(String a[]) {     System.out.println(arr[1];)     }     }  Which statement is correct?()

选项:A. When compilation some error will occur.B. It is correct when compilation but will cause error when running.C. The output is zero.D. The output is null.

💯:C

🔎:Given the following code:     public class Person{ static int arr[] = new int[10];  public static void main(String a[]) {     System.out.println(arr[1];)     }     }  Which statement is correct?()

选项:A. When compilation some error will occur.B. It is correct when compilation but will cause error when running.C. The output is zero.D. The output is null.

💯:C

🔎:以下哪种运算能从变量x中取得它的个位数

选项:A.x%10B.x/10C.x*10D.x-10E.x[10]F.x^10

💯:A

🔎:Java的字符类型采用的是ASCII编码。

选项:无选项

💯:错

🔎:java语言中不用区分字母的大写小写。()

选项:无选项

💯:错

🔎:Java 的各种数据类型占用固定长度,与具体软硬件平台环境无关

选项:A.正确B.错误

💯:A

🔎:中国大学MOOC: Java中数组的下标只能是各种整数数据类型

选项:

💯:错

🔎:一个数组可以存放不同类型的数值。()

选项:A.正确B.错误

💯:B

🔎:while循环的条件满足的时候循环继续,而do-while的条件满足的时候循环就结束了

选项:A.正确B.错误

💯:B

🔎:中国大学MOOC: int是比long窄的类型

选项:

💯:错

🔎:中国大学MOOC: boolean和int之间不能相互赋值

选项:

💯:错

🔎:中国大学MOOC: 数组的大小必须在写程序时就确定

选项:

💯:错

🔎:一旦数组被创建,大小就不能改变()

选项:

💯:√

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值