一些关于java读程序的练习题`
宝子们有疑问 评论区见哦~
`
1.关于Java的叙述中,正确的是( ac )
A.Java语言的标识符是区分大小写的
B.源文件名与public类名可以不相同
C.源文件扩展名为.java
D.源文件中public类的数目不限
2.以下( b )是应用程序的main方法头
public static int main(char args[ ])
public static void main(String a[ ])
public static void MAIN(String args[ ])
public static void main(String args)
3.下列哪些是合法的Java标识符名字(ad)
A. counterl B. $index, C. name-7
D. _byte E. 1array F. 2i
G. try H. char
4、
public class test { public static void main(String args[]) {
int x=1,y=1,z=1;
if (--x==0 && y++==1||z++==1)
System.out.println("x="+x+",y="+y+",z="+z); } }
运行结果:x=0,y=2,z=1
5.
int m=8,n=5; while (m>2) { if (m>n)
m = m-n; else n = n-m; } System.out.println(m+", "+n);
**运行结果:1,2**
6.
初始化部分和迭代部分可以使用逗号语句,来进行多个操作。所谓逗号语句是用逗号分隔的语句序列。
例如: for( int i=0, j=10;
i<j; i++, j-- ) {
System.out.println(i+", "+j); }
**结果 0,10 1,9 2,8 3,7 4,6**
7、
.public class Test3{ public static void main(String args[]) {
int f=1;
for (int k=2;k<4;k++)
f = f * k; System.out.println("f="+f); } }
**f=6**
8.
public class Test5{
public static void main(String args[]) {
for(int i=1;i<3;i++) {
for (int j=0;j<2;j++)
System.out.print("\t"+(i+j));
System.out.println();
}
}
}
1 2
2 3
9.
输出10~20之间不能被3或5整除的数
public class ContinueTest {
public static void main(String args[]) {
int j=9;
do {
j++;
if(j%3==0||j%5==0) continue;
System.out.print(j + " ");
} while(j<20);
}
}
11 13 14 16 17 19
10.outer:
for (int i=1;i<3;i++)
for (int j=1;j<4;j++)
{
if (i==1 && j==2)
continue outer;
System.out.println("i="+i+" j="+j);
}
i=1 j=1
i=2 j=1
i=2 j=2
i=2 j=3
11. 以下程序调试结果为? (d)
public class Test {
public static void main(String argv[]) {
int x[] = new int[2];
System.out.println(x[2]);
}
}
a.编译错误;
b.null
c.0
d.运行时出现异常 √
12.
以下代码的输出结果?
class test3{
public static void main(String args[ ]){
int[ ] a={1,2,3,4};
for (int i=0;i<4;i++)
a[i]=a[i]+i;
for(int b:a)
System.out.println(b);
}
}
1
3
5
7
13.填空题
等级考试上机题—输出结果为: 0 1 2 3 4 5 6 7 8 9
public class Java_3 {
public static void