云题海 - 专业文章范例文档资料分享平台

当前位置:首页 > java习题Ver2.0

java习题Ver2.0

  • 62 次阅读
  • 3 次下载
  • 2025/5/3 20:15:04

System.out.ptintln(\} }

Public static void main(String []args){ Aclass a=new Aclass(); Aclass a1=new Bclass(); a.go(); a.go(); }

}

以上程序运行结果是()

A.Aclass B.Bclass Aclass Bclass C.Aclass D.Bclass Bclass Aclass 15. 分析以下程序 Public class Test{

static void leftshift(int i,int j){

I<<=j; }

Public static void main(String []args){

int i=4,j=2; Leftshift(i,j);

System.out.println(i); } }

改程序的执行结果是() A.2 B.4. C.8. D.16

二、填空题

1、(16-33)、下面的程序的功能是从1~36的整数中随机选取7个数:第1次随机选择1~36中的一个数,第2次从剩下的35个数(第1次选中的数不包括其中)中随机选择一个数,…,重复这个过程,直到选中7个整数。请完成程序填空。

import java.util.*;

public class Select7From36 {

public static void main(String[] args) { Random rd= new Random();

ArrayList allNum=new ArrayList(); //创建有7个元素的Integer数组 Integer result[]=____(1)____; int x;

for(int i=1;i<=36;i++){

allNum.add(new Integer(i)); }

for(int i=0;i<=6;i++){ x=____(2)____;

result[i]=(Integer)allNum.get(x); allNum.remove(x); }

for(int i=0;i

System.out.print(result[i]+\ \ } } }

三、程序阅读题

1、(16-36)阅读下面的程序代码,并回答问题。 String s1=new String(\

String s2=new String(\ boolean b1=s1.equals(s2);

boolean b2=s1==s2;

System.out.print(b1+\ \

?程序段执行后,在命令行的输出结果如何? ?解释输出(1)的结果的原因?

四、编程题

1、编写两个类,其中一个类声明私有成员变量,并同时声明公共方法访问私有变量;另一个类中使用这些公共方法。

2、编写一个程序,将数组作为参数传给一个方法,该方法将这个数组的元素全部显示出来。

3、现在输入n个数字,以逗号分开,放入一个字符串中,然后按升序和降序排序,并显示排序结果。

练习四

一.程序阅读题

1、(16-37)、阅读下面的程序,并回答问题。

import java.io.*; public class Test {

public static void main(String args[]) throws IOException { BufferedReader buf=new BufferedReader(

new InputStreamReader(System.in)); while(true) {

String str=buf.readLine(); if(str.equals(\ break;

int x=Integer.parseInt(str); System.out.println(x*x); } } }

编译运行上面的程序:

?从键盘输入10,回车后输出的结果如何? 输出200

?从键盘输入exit,回车后程序能正确执行吗?为什么?

NumberFormatException 2、(16-38)、写出下面的程序编译、运行后的结果。

public class Test{

public static void main(String args[]) { new Student(\ new Student(\ new Student(\

System.out.println(\ Student.print(); } }

class Student {

protected String name; protected char sex;

protected int chinese; protected int english; protected Student next; static Student list;

Student(String name, char sex, int chinese,int english) { this.name=name; this.sex=sex;

this.chinese=chinese; this.english=english; this.next=list; list=this; }

static void print() { Student friend=list; if(friend==null)

搜索更多关于: java习题Ver2.0 的文档
  • 收藏
  • 违规举报
  • 版权认领
下载文档10.00 元 加入VIP免费下载
推荐下载
本文作者:...

共分享92篇相关文档

文档简介:

System.out.ptintln(\} } Public static void main(String []args){ Aclass a=new Aclass(); Aclass a1=new Bclass(); a.go(); a.go(); } } 以上程序运行结果是() A.Aclass B.Bclass Aclass Bclass C.Aclass D.Bclass Bclass Aclass 15. 分析以下程序 Public class Test{ static void leftshift(int i,int j){ I<<=j; } Public static void

× 游客快捷下载通道(下载后可以自由复制和排版)
单篇付费下载
限时特价:10 元/份 原价:20元
VIP包月下载
特价:29 元/月 原价:99元
低至 0.3 元/份 每月下载150
全站内容免费自由复制
VIP包月下载
特价:29 元/月 原价:99元
低至 0.3 元/份 每月下载150
全站内容免费自由复制
注:下载文档有可能“只有目录或者内容不全”等情况,请下载之前注意辨别,如果您已付费且无法下载或内容有问题,请联系我们协助你处理。
微信:fanwen365 QQ:370150219
Copyright © 云题海 All Rights Reserved. 苏ICP备16052595号-3 网站地图 客服QQ:370150219 邮箱:370150219@qq.com