作业答案(2)

2019-03-22 10:33

}

//7编写程序判断一个数是否为同构数据

public class Exam3 {

public static void main(String[] args) {

for(int i=10;i<=999;i++){

if ( i*i % 100==i || i*i*I 00==i ) }

System.out.println(i);

} }

//9编写程序练习将字符串转换为int、double类型,将数值类型转换为字符串类型。练习StringBuffer类的使用方法。 class StringExample

{ public static void main(String args[]) { String s1=new String(\ String s2=new String(\

int x =Integer.parseInr(s1); // 将s1转换为int类型

double y =Double.parseDouble(s2);; // 将s2转换为double类型

double z = x + y;

String s3 = new String(z); 或 String.valueOf(z);; //将z转换为字符串 StringBuffer StringBuffer(\

String s4 = new String(\

sbr.append(s4);; //将s4连接在sbr的

后面

System.out.println(sbr.toString()); //显示

为 Thingking in Java } }

二 、程序分析

sbr = new

1.写出下面程序的运行结果。 public class A{ private int x=50;

public void setX(int x){ this.x = x+50; }

public int getX(){ return x; } }

public class Tester {

public static void method1(A a){ a.setX(100); }

public static void method2(int x){ x = 50; }

public static void main(String[] args){ A a = new A(); method1(a);

System.out.println(a.getX()); int n = 10;

method2(n);

System.out.println(n); } }

2. 写出下面程序的运行结果。 import java.util.*; public class Ex2{

public static void main(String[] args){ Vector myList = new Vector(); myList.add(\ myList.add(\ myList.add(\ myList.set(2,\ myList.remove(0); myList.remove(0);

System.out.println(myList.get(0)); Hashtable ht = new Hashtable(); ht.put(\ ht.put(\

Iterator its = ht.values().iterator(); while(its.hasNext()){

System.out.println(its.next()); } } }

3. 写出下面程序的运行结果。 import java.util.*;

public class ArrayTester{

public static void main(String[] args){ int[] arrays1 = {1,3,5,7}; int[] arrays2 = {2,4,6,8}; int[] arrays3 = new int[4]; arrays2=arrays3;

for(int i=0;i

for(int i=0;i

}

4. 写出下面程序的运行结果。

class AAA

{ int add(int x,int y) { return x+y; } }

class BBB extends AAA { int add(int x,int y) { return x-y; } }

public class Exam8

{ public static void main(String args[]) { AAA a=new AAA();

System.out.println(a.add(66,44)); a=new BBB ();

System.out.println(a.add(66,44)); } }

5. 写出下面程序的运行结果。

public class Exam9 extends TT

{

public static void main(String args[]) {

Exam9 t=new Exam9 (\ }

public Exam9 (String s) {

super(s);

System.out.print(\ }

public Exam9 () {

this(\ } }

class TT {

public TT() {

System.out.print(\ }

public TT(String s) {

this();

System.out.print(\ } }

6. 写出下面程序的运行结果。

public class Exam10 {

String str=new String(\ char[] ch = {'a','b','c'};

public static void main(String args[]){ Exam10 ex = new Exam10(); ex.change(ex.str,ex.ch); System.out.println(ex.str+\ System.out.println(ex.ch); }

public void change(String str,char ch[]){ str = \ ch[0] = 'g'; } }

7. 指出下列程序运行的结果。 class Employee{

static void expenseAllowance(){

System.out.println(\}

class Manager extends Employee{ static void expenseAllowance(){

System.out.println(\}

class ex{

public static void main(String args[]){

Manager man = new Manager(); Employee emp1 = new Employee(); Employee emp2 = (Employee)man; man.expenseAllowance(); emp1.expenseAllowance();


作业答案(2).doc 将本文的Word文档下载到电脑 下载失败或者文档不完整,请联系客服人员解决!

下一篇:四年级科学下册 变来变去的盐教案 湘教版

相关阅读
本类排行
× 注册会员免费下载(下载后可以自由复制和排版)

马上注册会员

注:下载文档有可能“只有目录或者内容不全”等情况,请下载之前注意辨别,如果您已付费且无法下载或内容有问题,请联系我们协助你处理。
微信: QQ: