课程名称:
}
任课教师: 学号: 姓名:
------------------------------------------------------------------------------------------------------------------------ System.out.println(s); } class StringC { String s1; String s2;
StringC( String str1 , String str2 ) { s1 = str1; s2 = str2; } public String toString( ) { return s1+s2;} }
8.写出以下程序的运行结果。
class StringTest1 {
public static void main(String[] args) { } }
String s1=\
String s2=new String(\if(s1==s2){
System.out.println(\System.out.println(\}else{
9.以下程序段的输出结果为 。 import java.io.* ; public class abc {
public static void main(String args[ ]) { int i , s = 0 ;
int a[ ] = { 10 , 20 , 30 , 40 , 50 , 60 , 70 , 80 , 90 }; for ( i = 0 ; i < a.length ; i ++ )
if ( a[i]%3 = = 0 ) s += a[i] ; System.out.println(\ }
}
10.以下程序段的输出结果为 。
public class TestArray
{ public static void main(String args[ ]){ int i , j ; int a[ ] = {1,3,2,5,4}; for ( i = 0 ; i < a.length-1; i ++ ) { int k = i; for ( j = i ; j < a.length ; j++ ) if ( a[j]>a[k] ) k = j; int temp =a[i]; a[i] = a[k]; a[k] = temp; } for ( i =0 ; i
本题8页,本页为第6页 教务处试题编号:
课程名称:
任课教师: 学号: 姓名:
------------------------------------------------------------------------------------------------------------------------ System.out.print(a[i]+\ \ System.out.println( ); } }
11.以下程序段的输出结果为 。
class OverloadDemo{
void testOverload( int i ){
System.out.println(\ } void testOverload(String s){
System.out.println(\ } public static void main(String args[ ]){
OverloadDemo a=new OverloadDemo ( ); char ch='x';
a.testOverload(ch); } }
12.以下程序段的输出结果为 。 public class Test
{ public static void main(String[] args) { ClassB cb1=new ClassB(1); ClassB cb2=new ClassB(1); if(cb1==cb2){ System.out.println(\} else{ System.out.println(\ } }
class ClassB { int x; ClassB(int x){this.x=x; } }
五、程序设计题(本大题共10分),提示:请按照要求写出源程序代码,如果源程序代码中出现语法错误或逻
辑错误,则酌情扣分。
编写一个完整的Java Application 程序。包含接口ShapeArea,类Rectangle、Test,具体要求如下:
⑴接口ShapeArea: ①接口方法
double getArea():求一个形状的面积 double getPerimeter ():求一个形状的周长
⑵类Rectangle: 实现ShapeArea接口,并有以下属性和方法:
① 属性
width: double型,表示长方形的宽度 height:double型,表示长方形的长度
② 方法
Rectangle(double w, double h):构造函数 double getWidth():获取矩形的宽 double getHeight():获取矩形的高 double setWidth():设置矩形的宽 double setHeight():设置矩形的高
本题8页,本页为第7页 教务处试题编号:
课程名称:
任课教师: 学号: 姓名:
------------------------------------------------------------------------------------------------------------------------ toString():输出矩形的描述信息,如“width=1.0,height=2.0,perimeter=6.0,area=2.0”
⑶Test类作为主类要完成测试功能
① 生成一个Rectangle对象
② 调用这个对象的各个方法进行测试,验证各个方法的正确性 ③ 调用对象的toString方法,输出对象的描述信息
本题8页,本页为第8页 教务处试题编号:
百度搜索“70edu”或“70教育网”即可找到本站免费阅读全部范文。收藏本站方便下次阅读,70教育网,提供经典综合文库四川大学期末考试试题A卷(Java语言程序设计)(2)在线全文阅读。
相关推荐: