java第三次作业答案_Java程序设计第三次作业题及答案.doc

本文提供了Java第三次作业的详细解析,涵盖了字符串缓冲区操作、数组打印、命令行参数处理、异常捕获、循环控制、方法调用等多个核心知识点。通过实例分析,帮助读者深入理解Java编程的基本概念。
摘要由CSDN通过智能技术生成

Java程序设计第三次作业题及答案

第3次作业一、程序阅读题(本大题共40分,共 10 小题,每小题 4 分)1. public class test{ static StringBuffer sb1=new StringBuffer("Hello"); static StringBuffer sb2=new StringBuffer("Hello"); public static void main(String args[]){aMethod(sb1,sb2); System.out.println("sb1 is "+sb1);?System.out.println("sb2 is "+sb2); }?public static void aMethod(StringBuffer sb1,StringBuffer sb2){ sb2.append(" there");?sb1=sb2; } }2. public class test{?

?static int arr[] ={1,2,3,4,5};?public static void main(String args[])?{?System.out.println(arr[]); } }

3. public class Test{ public static void main(String[] args){ String foo=args[0];?String bar=args[1]; String baz=args[2]; System.out.println(baz);?}?} 如果执行语句 java Test Red Green Blue 后结果为4. 阅读以下程序:若执行命令:java AB heLLO,则输出为 ______ 。5. 请写下程序的输出结果:6. import java.io.*;public class Ppvg{?public static void main(String argv[]){? ?Ppvg p = new Ppvg( ); ? ?p.fliton( ); ?} ?public int fliton( ){? ?try{? ? ?FileInputStream din = new FileInputStream("P.java"); ? ? ?din.read( ); ?}catch(IOException ioe){? ? System.out.println("flytwick");? ? return 99;?}?finally{ ? ?System.out.println("fliton");?}?return -1; } } 如果P.java文件不存在,输出结果是什么?7. 指出下列程序运行的结果?public class BreakTest { public static void main(String args[] ) {?int count; for ( count = 1; count <= 10; count++ ) {if ( count == 8 ) break;?System.out.println( count );?}?}?}8. 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( );?} }9. 写出程序运行的结果.?class Parent{?void printMe( ){?System.out.println(“I’m parent”); }?}?class Child extends Parent{?void printMe( ){?System.out.println(“I’m child”);?} void printAll( ){ super.printMe( ); this.printMe( );?printMe( );?}?}?public class Test_this{?public static void main(String args[]){?Child myc=new

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值