1、运行结果:true小程序:import .*;public class a5 extends Applet Label lab1; TextField input1; int num1=1; public void init() lab1=new Label(任意输入310000的一个整数); input1=new TextField(10); add(lab1); add(input1); public boolean action(Event e,Object o) num1=(); showStatus( ( repaint();这个数是+num1); return true; publ
2、ic void paint(Graphics g) int xpos=50,ypos=50,i=0; int xpos1=xpos; while(num1!=1) if(num1%2=0) num1=num1/2; (num1), xpos, ypos); num1=num1*3+1; xpos=xpos+50; i+; if(i%5=0) ypos=ypos+10; xpos=xpos1;2.程序:public class a6 extends Applet Label lab; TextField input; int a,b,t2,t3,t4,t5,t6,t7,t8,t9,t10,t11
3、,t12; double i2,i3,i4,i5,i6,i7,i8,i9,i10,i11,i12; lab=new Label(输入次数 input=new TextField(10); add(lab); add(input); int time=();模拟次数+time); t2=t3=t4=t5=t6=t7=t8=t9=t10=t11=t12=0; for(int i=1;=time; a=(int)()*6+1); b=(int)()*6+1); switch(a+b) case 12:t12+; case 11:t11+; case 10:t10+; case 9:t9+; case
4、 8:t8+; case 7:t7+; case 6:t6+; case 5:t5+; case 4:t4+; case 3:t3+; case 2:t2+; i12=(double)t12/i; i11=(double)t11/i; i10=(double)t10/i; i9=(double)t9/i; i8=(double)t8/i; i7=(double)t7/i; i6=(double)t6/i; i5=(double)t5/i; i4=(double)t4/i; i3=(double)t3/i; i2=(double)t2/i; +xn/n!.三、实验步骤: 1程序:package
5、cp3;public class a1 extends Applet int a,b=new int20,i,j;输入数字 a=(); for(int i=0;a!=0; bi=a%10; a/=10; for(j=0;bj!j+); for(int t=-j;tt-) (bt),j*20-t*20,55); for(i=0; bi=0;* * * * * *2: Label lab1,lab2; TextField input1,input2; int a,b,i; double sum=0; public class aa int mult(int n) int s=1; for(int
6、j=1;j=n;j+) s*=j; return s;输入x大小 lab2=new Label(输入n值 input2=new TextField(10); add(lab2); add(input2); b=(); sum=0; aa c=new aa();=b; sum+=(double)(a,i)/(double)(i);结果为+sum);输入x=1,n=30时的运行结果:四二、 实验内容:1. 定义一个类,它包含了一个int类型的变量x、若干个构造函数(根据你的需要)和一个输出方法show()。 编程:从键盘输入一个数,将这个数传递给这个类的x,采用方法show()逆序输出这个数。2.
7、 定义一个整形集合类integerSet。这种类型的对象可以存储10个20至80之间的整数,即它的内部有一个整形数组存储数据。编程:(1)判断两个integerSet类对象S1和S2是否相等。提示:集合相等的前提是所有元素相等。(2)输出两个集合对象的交集。(3)输出两个集合对象的并集。(4)将一个整形数据插入到一个集合对象中。(5)从一个集合中删除某一个元素。1.程序 package cp4; class aa int x; aa(int n) x=n; void show() int b=0; for(;x! b=b*10+x%10; x/=10;public class a1 int v
8、alue=(); aa a1=new aa(value); ();1234554321成功构建 (总时间: 3 秒)package cp4;class integer int a=new int10; public void input() int i;=9; ai=(); if(ai=0) break; public void output() class uninteger int a=new int20;=19; class means int i,j; public boolean eq(integer a1,integer a2) ifi=0)j+) ifj=0) if(i!=j)
9、return false; ifi!=i) public void mix(integer a1,integer a2,integer mix) int t=0;i+) ifi=j) t+=i; else ifij) public void union(integer a1,integer a2,uninteger union) int t,s; i=0; for(s=0,t=0;s=9&ts!=0&t! ifs i+=t; t+;t+; if(s=0|s9)&(t(s i+=s+; public void insert(integer a1,int a) if(i=10) 此表已满不能插入
10、if(a=1;i-) i=i-1; 0=a; else if(a=i-1) i=a; if(a=j&a=j+1)j+1; j+1=a;插入后的表一变为:(); public void delete(integer a2,int a) ifa=0)所删位置无元素 for(j=a;i; j=j+1;删除后的表二变为:public class a5 public static void main(String args) boolean f; int a,b; integer mix=new integer(); uninteger union=new uninteger(); integer a1
11、=new integer(); integer a2=new integer();请以从小到大顺序输入两组(每组个数小于11个)2080之间的整数,分别以0,0结束表一为:表二为: means m1=new means(); f=(a1,a2); if(f)两个集合相等 else两个集合不相等 (a1,a2,mix); (a1,a2,union);两个集合的交为:两个集合的并为:请输入要插入表一的整数:a=(); (a1,a);请输入要删除表二元素的下标:b=(); (a2,b);*请以从小到大顺序输入两组(每组个数小于11个)2080之间的整数,分别以0,0结束213244567880314
12、621 32 44 56 78 80 0 0 0 0 31 46 56 80 0 0 0 0 0 0 两个集合不相等56 80 0 0 0 0 0 0 0 0 21 31 32 44 46 56 78 80 0 0 0 0 0 0 0 0 0 0 0 0 21 32 44 46 56 78 80 0 0 0 所删位置无元素 1 分钟 38 秒)五三、 实验内容1 写一个类,它具有一个protected数据成员。在同一个文件内再写第二个类,在这个类内编写一个方法, 以操作第一类内的protected数据;2. 采用public、private、protected以及友员等成员创建一个类,然后定义
13、这个类的一个对象。观察在访问所有类成员时会出现哪种类型的编译错误。三、实验步骤 1.程序/* */package cp5; a4_2 b=new a4_2();public class a4_1 int a1=1; public int a2=1; private int a3=1; protected int a4=1;public class a4_2 a4_1 a=new a4_1(); public void datause()data=+;public data= 序:class Test public String pub; private String pri; protecte
14、d String prot; String fri; Test() =publicprivateprotectedfriendly Test tmp=new Test();运行结果;publicException in thread main Uncompilable source code - pri可以在中访问private at Result: 1六四、 实验内容:1. 编写一个采用随机函数生成句子的游戏。现有4个字符串数组:article、noun、verb、preposition,它们的内容分别是:the、a、one、some、any;boy、girl、dog、town、cardro
15、ve、jumped、ran、walked、skippedto、from、over、under、依照句法要求:article+nounverbprepositionnoun产生20个句子。2. 从键盘输入几行文本做如下处理:(1) 显示各元音字母出现的次数。(2) 统计各个单词的长度。五、 实验步骤:1.程序package cp6;public class a3 String article=the,aonesomeany; String noun=boygirldogtowncar String verb=drovejumpedranwalkedskipped String prepositi
16、on=tofromoverunderon实验结果:the girl ran from one dogthe boy walked to some dogthe boy walked over the dogthe dog walked under a boysome girl ran under one boythe town ran under a towna town ran over the dogthe dog walked from some towna boy walked under a towna girl ran under the townone boy jumped fr
17、om a dogone girl jumped from the townthe girl drove from one girlthe boy ran under the boythe girl walked under one dogone boy drove over a towna boy ran to a townthe town drove under the girlsome boy ran to a boysome dog jumped to some dog 0 秒)2.程序class aa public void a1(String s) int i=0,j=0,t=0; int a=new int8;=()-1; if(i)!=)i+; else break; if(i=()字母个数为+()+t else if(a0=0&(i)= aj+=i-t; t=i; aj+=i-t-1; aj=i-t-1;字母个数分别为ai! t=0; if(i)=a|(i)=ieou元音字母个数为+t);public class a6 aa a1=new aa();请输入几行字符串 String s1=new String(); String s2=new String(); String s3=new String
copyright@ 2008-2022 冰豆网网站版权所有
经营许可证编号:鄂ICP备2022015515号-1