黄老师 发表于 2020-5-4 08:00:00

《Java程序设计》20春重庆大学第3次

1.[主观题]public class Leaf{private int i=0;Leaf increment( ){i++;return this;}void print( ){System.out.println(“i=”+i);}public static void main(String args[]){Leaf x=new Leaf( );x.increment( ).increment( ).increment( ).print( );}}

    正确答案:————
2.[主观题]class Mystery {private long val;public Mystery(long v) {val = v;}public static void main(String args[]){Mystery x = new Mystery(10L);Mystery y = new Mystery(10L);Mystery z = y; long a = 10L;int b = 10;System.out.println("the value1="+(y==z));System.out.println("the value2="+(y==x));}}

    正确答案:————
3.[主观题]文件file.txt的内容为: How are you ?

    正确答案:————
4.[主观题]public class test { public static void main(String argv[]){boolean b1 = true;if((b1 ==true) || place(true)){ System.out.println("Hello Crowle"); } }public static boolean place(boolean location){if(location==true){ System.out.println("Borcetshire"); }System.out.println("Powick");return true;}}

    正确答案:————
5.[主观题]public class demo{ public static void main(String args[]){ int bookno=0; while (bookno<=100){ bookno+=10; if (bookno==40) break; System.out.println(“the bookno is”+bookno); } System.out.println(“This is the end”); } }

    正确答案:————
6.[主观题]import java.awt.Graphics; import java.applet.Applet;public class ttt extends Applet{public void paint( Graphics g ){int count, xPos = 25;for ( count = 1; count <= 10; count++ ){if ( count == 8 ) break;g.drawString( " " + count, xPos, 25 );xPos += 10;}} }问题:程序的输出结果是什么?

    正确答案:————
7.[主观题]public class Calc { public static void main (String args []) { int total = 0; for (int i = 0, j = 10; total > 30; ++i, --j) { System.out.println(" i = " + i + " : j = " + j); total += (i + j); } System.out.println("Total " + total); } }

    正确答案:————
8.[主观题]public class test {public static void main(String[] args) {StringBuffer a=new StringBuffer("A");StringBuffer b=new StringBuffer("B");operate(a,b);System.out.println(a+","+b);}public static void operate(StringBuffer x, StringBuffer y) {x.append(y);y=x;}}

    正确答案:————
9.[主观题]public class Test {public static void main(String[] args) {String foo=args;String bar=args;String baz=args;System.out.println(baz);}}如果执行语句 java Test Red Green Blue 后结果为

    正确答案:————
10.[主观题]class Vehicle{public void drive(){System.out.println("Vehicle: drive");}}class Car extends Vehicle{public void drive(){System.out.println("Car: drive");}}public class Test {public static void main (String args []){Vehicle v;Car c;v = new Vehicle();c = new Car();v.drive();c.drive();v = c;v.drive();}}

    正确答案:————
11.[主观题]简述线程与进程的区别。

    正确答案:————
12.[主观题]如何构造一个线程(两种方法)?

    正确答案:————
13.[主观题]什么是串行化,如何进行串行化?

    正确答案:————
14.[主观题]什么是接口,它的主要作用是什么?

    正确答案:————
15.[主观题]import java.awt.*;import java.applet.*;public class Test51` extends Applet{float[ ] x ={1.2, 3.4, 5.6, 7.8}; public void paint(Graphics g){int s=0;for( int i = 0; i < x.length; i++ ) s += (int)x;g.drawString(" " + s, 30, 60);}}问题: 1)程序的输出结果是什么? 2)方法paint()中的循环体 s += (int)x; 能写为 s +=x; 吗? 为什么?

    正确答案:————
16.[主观题]编写一个程序,接受用户从键盘输入的10个整数,并输出这10个整数的最大值和最小值。

    正确答案:————
17.[主观题]编写程序求所有指定浮点数的平均值,要求所有浮点数均通过命令行参数传入(如java test 11.1 22.2 33.3 44.4).

    正确答案:————
18.[主观题]编写程序使用类StringBuffer的replace方法将字符串”Mary was a ”改为”Mary had a book.”

    正确答案:————
19.[主观题]编程实现从键盘输入字符串,并统计其中数字字符个数的功能

    正确答案:————
20.[主观题]创建一个Applet,要求在init方法中向该applet添加一个文本输入区组件,该文本输入区中显示字符为“你好”,行数为10,列数为15.

    正确答案:————


页: [1]
查看完整版本: 《Java程序设计》20春重庆大学第3次