还剩53页未读,继续阅读
本资源只提供10页预览,全部文档请下载后查看!喜欢就下载吧,查找使用更方便
文本内容:
百分制分数到等级分数1package pm;public classSwitchTest{〃编写程序,实现从百分制分数到等级分数的转换////=90A//80〜89B//70〜79C//60〜69D//60Epublic static void mainString[]args{int s=87;switchs/10{case10:System.out.printlnnAn;break;case9:System.out.printlnnA,;break;case8:System.out.printlnnBn;break;case7:System.out.printlnncn;break;case6:System.out.printlnnD;break;default:System.out.println,E,;break;成法口诀阵形2package pm;public classSwitchTest{public static void mainString[]args{forint i=l;i=9;i++{forintj=l;j=i;j++{System.out.printj+”*”+i+”=+i*j+“\t;public staticvoid mainString[]args{int SIZE=19;forint i=0;iSIZE;i++{ifi10{System.out.printn+i;〃两个空格}else{两个空格System,out.print,”+chari+H-10;//System.out.println;//System.out.printi10chari+0:chari+,a,-10;forint i=0;iSIZE;i++{ifi10{System.out.printi+n*;//一个空格}else{”;〃一个空格System.out.printchari+a-10+;//两个空格forint j=O;jSIZE;j++{System.out.print“*“+System.out.printlnO;数组输出唐诗10package day04;public class ArrayTest{public staticvoid mainString[]args{char[][]arr=new char
[4]
[7];朝辞白帝彩云间千里江陵一日还两岸猿声啼不住轻舟已过万重山”;String s=forint i=O;iarr.length;i++{forint j=O;jarr[i].length;j++{arr[i][j]=s.charAti*74-j;forint i=0;iarr|0].length;i++{forint j=O;jarr.length;j++{System.out.printarr[arr.length-j-1]
[1]+,;System.out.printlnO;找出满意条件的最小数11package day02;public classFangk{public staticvoid mainString[]args{//forint i=1000;iv=9999;i++{//int q=i/1000;//int b=i/100%10;//int s=i/10%10;//int g=i%10;//ifqbsgq+g==b+sb%2!=0{//System.out.printlnHThe MinNumber is:+i;//break;////loop1:forint q=1;qv=9;q++{loop2:forint b=0;b=9;b++{ifb%2=0{continue loop2;forint s=0;sv=9;s++{forint g=0;g=9;g++{ifqbsgq+g==b+s{System.out.printlnHThe is:”+q*1000+b*100+s*10+g;Min Numberbreakloop1;推断一个数是否是素数12package day02;public classFangk{public staticvoid mainString[]args{int num=14;boolean flag=true;forint i=2;i=num/2;i++{ifnum%i==0{二flag false;break;ifflag{System.out.printlnnum4-n isa prime number!1;}else{System.out.printlnnum+n isnot a prime number!*;IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIHpackage day04;import java.util.Scanner;public classAl{public staticvoid mainString[]args{int n;二Scanner seanew ScannerSystem.in;System.out.printlnHplease inputa number:;n=sca.nextlnt;ifisPrimeNumbern{System.out.printlnn4-nis aprimenumber!1;}else{System.out.printlnn+nis notaprimenumber!n;public staticboolean isPrimeNumberint n{forint i=2;i=n/2;i++{ifn%i==0{return false;return true;一个数倒序排列13package day02;public classDaoxu{public staticvoid mainString[]args{int olddata=3758;int newdata=0;whileolddata!=0{forint i=0;i4;i++{newdata=newdata*10+olddata%10;olddata=olddata/l0;System.out.printlnnnewdata=H-i-newdata;将一个整数以二进制输出14package day04;import java.util.Scanner;public classArrayTest{public staticvoid mainString[]args{int n;Scanner s=new ScannerSystem.in;System.out.printlnnplease inputa number:1;n=s.nextlnt;forint i=31;i=0;i—{ifnl«i!=0{System.out.printH In;}else{System.out.print,On;if32-i%8==0{System.out.printH n;}}矩形图案15package day02;public classFangk{public staticvoid mainString[]args{int m=5,n=6;〈forint i=0;i n;i++{,*;System.out.println;forint i=0;im-2;i++{,*;forint j=0;jn-2;j++{;System,out.print}*;System,out.printSystem.out.println;forint i=0;in;i++{*;猜数字16package day02;import java.util.Scanner;public classCsz{public staticvoid mainString[]args{Scanner s=new ScannerSystem.in;int num=int Math.random*1000;int m=0;forint i=9;i=0;i-{System.out.printlnplease inputyour number!n;m=s.nextlnt;ifmnum{System.out.printlnnToo large!n;}else ifmnum{System.out.printlnnToo small!;}else{System,out.printing Youare right!1;break;ifi0{还有“次机会!”;+i+”if m!=num{下次再来吧!;
17.HotelManagerpackage hotel;import java.util.Scanner;public classHotelManager{表示房间private static String[][]rooms;//public staticvoid mainString[]args{rooms=new Stringl10]
[12];表示用户输入的吩咐String comm;//for int i=0;irooms.length;i++{二for int j=0;jrooms
[0].length;j++{rooms[i][j]EMPTY”;//while true{请输入吩咐”;Scanner sea=new ScannerSystem.in;System.gc;comm=sca.next;if nsearchn.equalsIgnoreCasecomm{search;}else if ninn.equalsIgnoreCasecomm{int roomNo=sca.nextlnt;String name=sca.next;inroomNo,name;}else if noutn.equalsIgnoreCasecomm{int roomNo=sca.nextlnt;outroomNo;}else if nexitn.equalsIgnoreCasecomm{System,out.printin程序退出break;}else{吩咐输入错误,请重新输入”;private staticvoid outintroomNo{ifnEMPTYn该房间没有客人入住,退房失败!”;return;]二rooms[roomNo/l00-1][roomNo%100-1EMPTY”;退房胜利System.out.printlnroomNo+!;private staticvoid inintroomNo,String name{if!nEMPTYH该房间已经有客人入住!”;return;rooms[roomNo/100-1][roomNo%100-1]=name;胜利入住房间!System.out.printlnname++roomNo+;private staticvoid search{〃打印房间号for int i=0;irooms.length;i++{for intj=0;jrooms
[0].length;j++{System.out.printi+1+”0”+j+1+”;}else{System.out.printi+1++j+1+”}〃打印房间状态System.out.println;for intj=0;jrooms
[0].length;j++{System.out.printrooms[i][j]+;System.out.println;
18.StudentManager packageday
05.student_manager;import java.util.Scanner;public class StudentManager{static int[][]scores=new int
[6]
[5];static String[]students={Hzhangsann,nlisi,Vwangwun,nzhaoliu,V,qianqin,nliubaH};二{staticString!]courses corejava”Jjdbc,servlet JjspJejb};public staticvoid mainString[]args{forint i=0;iscores.length;i4-+{forint j=0;jscores[i].length;j++{scores|i][j]=intMath.random ic100;Scanner s=new ScannerSystem.in;String comm;whiletrue{请输入吩咐*,;System.out.printlncomm=s.next;ifcomm.equalsn AVGn{String para=s.next;avgpara;}else ifcomm.equalsSORT,{String course=s.next;sortcourse;}else ifcomm.equalsGETH{String student=s.next;String course=s.next;getstudent,course;}else ifcomm.equalsEXITn{break;}else{吩咐格式不正确,请重新输入!”;}}//main end!public staticvoid avgStringpara{int slndex=-l;int clndex=-l;二forint i=O;istudents.length;i++{ifstudents[i].equalspara{slndex i;ifslndex==-1{forint i=0;icourses.length;i++{ifcourses[i].equalspara{clndex=i;ifslndex==-lclndex=-l{找不到学生或课程!”;return;double avg=
0.0;ifslndex!=-l{forint i=0;iscores[sIndex].length;i++{avg+=scores[slndex]|i];avg/=scores[slndex].length;学生的平均分是:+para+”+avg;}else{forint i=0;iscores.length;i++{avg4-=scoresfi]fclndex];avg/=scores.length;课程的平均分是:System,out.printin+para+”+avg;public staticvoid sortString course{int[]courseScore=new int[scores.length];〃假如求总分的排名ifcourse.equalssum{//〃求出每个学生的总分,将成果存放在数组中courseScoreforint i=0;iscores.length;i4-+{int studentSum=O;forint j=0;jscores[i].length;j+4-{studentSum+=scores华氏和摄氏的转换法3package pm;import java.util.Scanner;public classSwitchTest{public staticvoid mainString[]args{Scanner sc=new ScannerSystem.in;while true{”请输入要转换的温度类型或C F;String s=sc.next.trim;if ncH.equalsIgnoreCases{〃做摄氏向华摄的转换System.out.println”请输入要转换摄氏的温度:double db=sc.nextDoubleQ;double db2=db*9/5+32;对应的华氏温度:“+db2+“F;}else if nf,.equalsIgnoreCases{//做华摄向摄氏的转换”请输入要转换华氏的温度:System.out.printindouble db=sc.nextDoubleQ;double db2=db-32*5/9;System.out.println对应的摄氏温度:+Math.rounddb2+nCn;}else ifnexitn.equalsIgnoreCases{break;courseScore[i]=studentSum;{〃假如不是求总分排名}elseint clndex=-l;找到这门课程的下标forint i=0;icourses.length;i++{//ifcourses[i].equalscourse{clndex=i;}〃假如是一门有效的课程ifclndex!=-1{〃把数组中这一列的值放到数组中!scores courseScoreforinti=0;iscores.length;i++{courseScoreli]=scoresliJ[cIndex];{〃假如不是一门有效的课程}else课程名不正确,请重新输入!return;String[]studentCopy=new String[students.length];System.arraycopystudents,0,studentCopy,0,students.length;forint i=0;icourseScore.length-1;i++{forint j=i+1;jcourseScore.length;j++{ifcourseScore[i]courseScore[j]{inttemp=courseScore[i];courseScore|i|=courseScore[j];courseScore[j]=temp;String stemp=studentCopy[i];studentCopy[i]=studentCopy[j];studentCopy[j]=stemp;int order=l;名次学生成果”;\t\tforint i=0;icourseScore.length;i++{ifi!=0courseScore[i]==courseScore[i-1]{order—;}else{order=i+l;System.out.printorder+n\tn;System.out.printstudentCopy[i]+n\tn;System.out.printlncourseScore[i];order++;public staticvoid getString student,Stringcourse{int slndex=-l;int clndex-1;forint i=O;istudents.length;i++{ifstudents|i|.equalsstudent{slndex=i;}ifslndex==-l{没有这个学生:”System,out.printin+student;return;{〃假如求总分ifcourse.equals”sum”int studentSum=O;forint j=0;jscores[sIndex].length;j++{studentSum+=scores[sIndex][j];学生的总分为System.out.printlnstudent+””+studentSum;return;forint i=0;icourses.length;i++{ifcourses[i|.equalscourse{clndex=i;ifclndex==・l{没有这门课程:System,out.printin”+course;return;System.out.printlnstudent+n学生的+course+课程的成果为M+scores[sIndex][clndex];
19.Five packagehotel;import java.util.Scanner;/**首先在程序第一次运行的时候,构建出棋盘,切以后*不能再从新构建,知道结束,所以将其放到静态代码块中**@author zhz**/public classFive{〃由于矩阵要保存输入的信息,所以要设置成全局变量,整个程序就一个private staticString[][]five=new String
[17]
[17];static{〃构建并打印棋盘drawFive;public staticvoid mainString[]args{〃请白棋下子whiletrue{请白棋下子”;System,out.printinPoint pl=pleaseln;*{无if!five[lnteger.parselntp1,getX][Integer.parselntp l.getY].equals效的位置,视为自动放弃runPointp1/white1;gameoverpl;请黑棋下子”;System,out.printin Point p2=pleaseln;if!five[Integer.parseIntp
2.getX][Integer.parseIntp
2.getY].equals,*,无效的位置,视为自动放弃”;runPointp2,nblackH;gameoverp2;〃依据用户的输入信息,对棋盘的坐标进行赋值,白棋@黑棋并且将当前棋盘的信息输0,出private staticvoid runPointPointp,String str{//依据来获得行和列的坐标px pyint x=Integer.parseIntp.getX,y=Integer.parseIntp.getY;ifstr.equalsn white{five[x][y]=n@n;}else{five[x][y]=O;outFiveQ;//用户输入要放棋子的坐标并且自动转换为详细的坐标private staticPoint pleaseln{Scanner sc=new ScannerSystem.in;Pointp=new Pointsc.next,sc.next;String px=p.getX;String py=p.getY;〃依据来获得行和列的坐标px pyintx=O,y=O;forint i=l;ifive.length;i++{iffive[i]
[0].equalspx{x=i;iffive[O|[i].equalspy{y=i;return newPointx+””,y+””;}/**推断输赢,依据当前点,起先计算,假如有五个点连成线,则盛,程序提示结束,并显示输赢*@param ppublic staticvoidgameoverPoint p{intx=Integer.parseIntp.getX,y=Integer.parseIntp.getY;int cl=0,c2=0,c3=0,c4=0;boolean11=true,12=true,13=true,14=true,15=true,16=true,17=true,18=true;for int i=1;i5;i++{//竖直向上if y-i=1five[x][y-i].equalsfive[x][y]11{cl++;}else{11=false;//竖直向下if y+i=16five[x][y+i].equalsfive[x][y]12{cl++;}else{12=false;//水平向左if x-i=1five[x-i][y].equalsfive[x][y]13{c2++;}else{13=false;//水平向右if x+i=16five[x+i][y].equalsfive[x][y]14{c2++;}else{14=false;//斜向左上if x-i=1y-i=1five[x-i][y-i].equalsfive[x][y]15{c3++;}else{15=false;//斜向右下if x+i=16y+i=16five[x+i][y+i].equalsfive[x][y]16{c3++;}else{16=false;//斜向左下if x-i=1y+i=16five[x-i][y+i].equalsfive[x][y]17{c4++;}else{17=false;//斜向右上if x+i v=16y-i=1five[x+i][y-i].equalsfive[x][y]18{c4++;}else{18=false;if cl=4||c2=4||c3=4||c4=4{if five[x][y].equalsnr{黑棋获胜!System.out.println—System.exitO;}else{“白棋获胜!”;System.exitO;〃构造棋盘private staticvoid drawFive{〃构建棋盘边框String[]sr=new String{”five
[0]=sr;forint i=O;ifive.length;i++{five[i][O]=sr[i];〃构建棋盘内容forint i=1;ifive.length;i++{叫;forint j=l;jfive[O].length;j++{〃打印棋盘outFive;〃打印棋盘private staticvoid outFive{forint i=O;ifive.length;i++{forint j=O;jfive
[0].length;j++{System.out.printfive[i][j]+“;System.out.printlnO;2O.CardGamepackage dayO
5.cardGame;import java.util.Scanner;public classCardGame{static int[]twoHandsCards=new int
[6];static intuserAMoney=0;static intuserBMoney=0;public staticvoid mainString||args{Scanner s=new ScannerSystem.in;请输入总赌本;userAMoney=s.nextInt;userBMoney=userAMoney;int currentMoney=0;whileuserAMoney0userBMoney0{请输入本局赌注”;currentMoney=s.nextInt;ifcurrentMoney=0||currentMoneyuserAMoney||currentMoneyuserBMoney{赌注不正确,请重新输入!continue;dispatchCards;printCardstwoHandsCards;ifcompare0{userAMoney+=currentMoney;userBMoney-=cuiTentMoney;玩家获胜!”;}else ifcompare0{userAMoney-=currentMoney;userBMoney4-=currentMoney;电脑获胜!”;}else{平局!”;玩家赌本“userAMoney+”;电脑赌本n+userBMoney;public staticvoid dispatchCards{inti=0;whileitwoHandsCards.length{int h=intMath.random*4+l;int d=intMath.random*13+2;intj=0;for;ji;j++{iftwoHandsCards[j]==h*100+d{break;}ifg{continue;}else{twoHandsCards[i++]=h*100+d;public staticvoid printCardsint[]oneHandCards{forint i=0;ioneHandCards.length;i+-i-{switchoneHandCards[i]/100{case l:System.out.printn1^n;break;case2:System.out.printn^EH;break;case3:System.out.printnWH;break;case4:System.out.printnZ/*;break;}ifoneHandCards[i]%l00=10{System.out.printoneHandCards[i]%100;}else{switchoneHandCards[i]%100{case11:System.out.printnJn;break;case12:System.out.printQ;break;case13:System.out.printnKn;break;case14:System.out.printHAn;break;System.out.print,;System.out.println;public staticint compare{int[]aCards=new int
[3];int[]bCards=new int
[3];forint i=0;i3;i++{aCards[i]=twoHandsCards[i];forint i=3;i6;i++{bCards[i-3]=twoHandsCards[i];return fromCardsToNumberaCards-fromCardsToNumberbCards;public staticint fromCardsToNumberint[]oneHandCards{forint i=0;ioneHandCards.length-1;i++{forint j=i+1;joneHandCards.length;j++{ifoneHandCards[i]%100oneHandCards[j]%100{int temp=oneHandCards[i];oneHandCards[i]=oneHandCards[j];oneHandCards[j]=temp;}int num=0;ifoneHandCards
[0]%100==oneHandCards[l]%100oneHandCards
[1]%100==oneHandCards
[2]%100{num=6*1000000+oneHandCards
[0]%100*10000+oneHandCards
[1]%100*100+oneHandCards
[2]%100;}else ifoneHandCards
[0]/100==oneHandCards
[1]/100oneHandCards[l]/100=oneHandCards
[2]/100oneHandCards|0|%l00==oneHandCards11]%100+1oneHandCards11%100==oneHandCards12]%100+1{num=5*1000000+oneHandCards
[0]%100*10000+oneHandCards
[1]%100*100+oneHandCardsQ]%100;}else ifoneHandCards
[0]/l00==oneHandCards
[1]/l00oneHandCards
[1]/100==oneHandCards
[2]/100{num=4*1000000+oneHandCards
[0]%100*10000+oneHandCards
[1]%100*100+oneHandCards
[2]%100;}else ifoneHandCards
[0]%100==oneHandCards
[1]%100+1oneHandCards[l]%l100+l{num=3*1000000+oneHandCards
[0]%100*10000+oneHandCards
[1]%100*100+oneHandCardsQ]%100;Jelse ifoneHandCards
[0]%100=oneHandCards
[1]%100{num=2*1000000+oneHandCards
[0]%100*10000+oneHandCards
[1]%100*100+oneHandCards
[2]%100;Jelse ifoneHandCards11]%100==oneHandCards
[2]%100{num=2*1OOOOOO+oneHandCardst1]%100*10000+oneHandCards
[2]%100*100+oneHandCards
[0]%100;}else{num=1*1000000+oneHandCards
[0]%100*10000+oneHandCards
[1]%100*100+oneHandCarpackage pm;import java.util.Scanner;public classSwitchTest{public staticvoid mainString[]args{Scanner sc=new ScannerSystem.in;boolean flag=true;while flag{”请输入要转换的温度,如50c或100fn;String str=sc.nextLine.trim;ifstr.endsWithncn||str.endsWithnCH{//做摄氏向华摄的转换30cString st=str.substringO,str.length-1;double db=Double.parseDoublest;//[0,2//2double db=Double.valueOfst.doubleValue;double db2=db*9/5+32;对应的华氏温度:“+db2+F;}else ifstr.endsWithnr||str.endsWithnFn{//做华摄向摄氏的转换String st=str.substringO,str.length-1;double db=Double.parseDoublest;//[0,2//2double db=Double.valueOfst.doubleValue;double db2=db-32*5/9;对应的摄氏温度+Math.rounddb2+*Cn;}else ifnexitn.equalsIgnoreCasestr{flag=false;}三个数的最大数4package pm;public classSwitchTest{public staticvoid mainString[]args{int a=l,b=2,c=3,d=0;d=aba:b;ds
8、求2/1+3/2+5/3+8/5+13/8・・・・・前20项之和class Sum{public staticvoid mainSting|]args{double sum=0;〃初始的分子分母double fenZi=
2.0,fenMu=
1.0;fenZi=2,fenMu=1forint i=l;i=20;i++{sum+=fenZi/fenMu;〃下一项的分母=上一项的分子fenMu=fenZi;fenZi+=fenMu;〃下一项的分子=上一项的分子加分母System.out.printlnnsum=sum;、利用程序输出如下图形:9*1**1**1*!^*T**7**T*―
1.■1,«X»1**T**Tw****class Asteriskpublic staticvoid mainString[J args{for inti=l;i=13;i+=2{*;}//换行System.out.println;}、计算圆周率11PI=4—4/3+4/5-4/
7.……打印出第一个大于小于的值
3.
14153.1416class Pi{public staticvoid mainString||args{〃定义初始值double pi=0;〃分子为double fenZi=4;4//第一个可看作分母为的分式,以后的分母每次递增double fenMu=1;4,12运行老久,削减循环次数会快许多,只是精确度小些for inti=0;i1000000000;i++{//pi+=fenZi/fenMu;〃每项分子的变更是fenZi*=-
1.0;+4,—4,+4,—
4....//分母的变更是每项递加fenMu+=
2.0;1,3,5,7,....2System.out.printlnpi;}输出结果为应当不精确pi=
3.14504,、输入一个数据计算斐波那契数列的第个值12n,Fibonacci n112358132134规律一个数等于前两个数之和〃计算斐波那契数列的第个值Fibonacci npublic class Fibonacci{public staticvoid mainStringargs[]{int n=Integer.parseIntargs[O];第一个数int nl=1;//其次个数int n2=1;//〃和int sum=0;ifn=0{参数错误!System,out.printin return;ifn=2{sum=1;}else{forint i=3;i=n;i++{sum=nl+n2;nl=n2;n2=sum;}System.out.printlnsuiYi;〃计算斐波那契数列的第个值Fibonacci n〃并把整个数列打印出来public classFibonacciPrint{public staticvoid mainStringargs[]{int n=Integer.parselntargs
[0];FibonacciPrint t=new FibonacciPrint;forint i=l;i=n;i++{t.printi;public void printint n{〃第一个数int nl=1;其次个数int n2=1;//〃和int sum=0;ifn=0{参数错误!”;System,out.printin return;ifn=2{sum=1;}else{forint i=3;i=n;i++{sum=nl+n2;nl=n2;n2=sum;System.out.printlnsum;、求的值131-1/3+1/5-1/7+1/9……求出前项和值a,50求出最终一项肯定值小于的和值b,le-
5、在屏幕上打印出行的金字塔图案,如,若则图案如下15n n=5,****•卜■;、
4、•[、,]、〃、,,、〃打印金字塔图案public classPrintStar{public staticvoid mainStringargs[]{int col=Integer.parseIntargs[O];表示行数forint i=l;i=col;i++{//i〃打印空格forint k=0;kcol-i;k++{System.out.printH n;〃打印星星forint m=0;m2*i-1;m++{*;System,out.printSystem.out.printlnO;、歌德巴赫猜想,任何一个大于六的偶数可以拆分成两个质数的和打印出全部的可能16〃任何一个大于六的偶数可以拆分成两个质数的和〃打印出全部的可能public classGedebahe{public staticvoid mainStringargs[]{int num=Integer.parselntargs
[0];ifnum=6{参数错误!”;System,out.printinreturn;ifnum%2!=0{参数错误!”;System,out.printingreturn;Gedebahe g=new Gedebahe;不是质数是偶数,因此从起先循环//I,23forint i=3;iv=num/2;i++{{〃假如为偶数,退出本次循环ifi%2==0continue;〃当及都为质数时,满意条件,打印i num-i ifg.isPrimeig.isPrimenum-i{System.out.printlni+n+n+num-i+=+num;第章数组4定义一个型的一维数组,包含个元素,分别赋一些随机整数,然后求出全部元素的最
1.int10大值,最小值,平均值,和值,并输出出来classArrayNumber{public staticvoid mainString[]args{int[]arrayNumber;array Number=new int
[10];以下是随机的个整数”;10〃填入随机的个整数10for inti=0;iarrayNumber.length;i++{arrayNumber[i]=int100*Math.random;System.out.printarrayNumber[i]+n;System.out.println;int max=arrayNumber
[0];int min=arrayNumber
[0];int sum=0;for inti=0;iarrayNumber.length;i++{ifmaxarrayNumber[i]〃求最大值max=arrayNumber[i];ifminarrayNumber[i]〃求最小值min=arrayNumber[i];sum+=arrayNumber[i];其中二Max+max+”,Min=+min+”,Sum=+sum+”,Avg=+sum/
10.0;.定义一个型的一维数组,包含个元素,分别赋值为然后将数组中的元素都向前2int101-10,移一个位置,即,凯用口]=最终一个元素的值是原来第一个元素的值,然后输出这个数组2
[0]=1]2
[2],...定义一个型的一维数组,包含个元素,用来存储每个学员的成果,循环产生个
3.int40400〜之间的随机整数,100将它们存储到一维数组中,然后统计成果低于平均分的学员的人数,并输出出来(选做)承上题,将这个成果依据从高到低的依次输出出来
4.40(选做)编写程序,将一个数组中的元素倒排过来例如原数组为则倒排后数组5,1,2,3,4,5;中的值为5,4,3,2,lo要求定义一个血型数组包含个元素,保存个随机的位数再定义一个型数组6,a,1001004int b,包含个元素统计数组中的元素对求余等于的个数,保存到中;对求余10a100b
[0]10等于的个数,保存到中,……依此类推1b[l]class Remain{()public staticvoidmainString!]args{int[]a=new int
[100];//保存个随机位数到中1004afor inti=0;ia.length;i++{a[i]=int1000*Math.random;〃统计数组中的元素对求余的各个的数目a10int[]b=new int|10];int k,sum;for intj=0;jb.length;j++{for k=0,sum=0;ka.length;k++{if a[k]%10==j sum++;b[j]=sum;Sy stem.out.printfn b[%d]=%d\nn,j,b[j];}定义一个的二维数组,用来存储某班级位学员的门课的成果;这门课按存储依次7,20*52055依次为和core C++,core Java,Servlet,JSP EJB循环给二维数组的每一个元素赋之间的随机整数10〜100依据列表的方式输出这些学员的每门课程的成果2要求编写程序求每个学员的总分,将其保留在另外一个一维数组中3要求编写程序求全部学员的某门课程的平均分4class Student{public staticvoid mainString[]args{int[][]mark=new int
[20]
[5];//给学生赋分数值,随机生成for inti=0;}//未完成完成九宫格程序8,在井字形的格局中只能是奇数格局,放入数字数字由,使每行每列以及斜角线的和都相等阅历规则从起先按依次逐个填写;放在第一行的中间位置;下一个数往右上角度1145处填写;假如单边越界则按头尾相接地填;假如有填写冲突,则填到刚才位置的底下一格;d=abaca:c:bcb:c;最多数为”+d;简洁计算器的小程序5package one;import java.awt.BorderLayout;import java.awt.GridLayout;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import javax.swing.JButton;import javax.swing.JFrame;import javax.swing.JPanel;import javax.swing JTextField;public classJsq implements ActionListener{private JFrame frame;private JButtonf]bus;private JTextFieldjtx;private JButton bu;private char[]strs;private Stringd_one=”;private Stringoperator;public staticvoid mainString[]args{new Jsq;假如有两边越界,则填到刚才位置的底下一格个人认为,可以先把最中间的数填到九宫格的最中间位置;再按上面的规则逐个填写,而且填的时候还可以把头尾对应的数填到对应的格子中第个值跟倒数第个值对应,n n格局上以最中间格为轴心对应这样就可以同时填两个数,效率比之前更高;其正确性有待数学论证但多次试验之后都没发觉有错九宫格的至少还可以填在另外的三个位置,只是接下来的填写依次须要相应变更;1再依据九宫格的对称性,至少可以有种不同的填写方式8import java.util.Scanner;class NinePalace{public staticvoid mainString[]args{//定义为九宫格的行列数,须要输入N请输入九宫格的行列规模只能是奇数的”;Scanner n=new ScannerSystem.in;int N;//推断格局是否奇数可推断出偶数、负数及小数double d;while true{d=n.nextDoubleQ;N=intd;if d-N
1.0E-4||N%2==0||N0输入出错格局只能是正奇数请重新输入}else break;〃老师的九宫格填写方法〃定义保存九宫格的数组int[][]result=new int[N][N];行初始位置int row=0;//列初始位置,因为列由起先,故是中间位置int col=N/2;//0N/2for inti=l;iv=N*N;i++{result[row][col]=i;row-;col++;行列都越界if row0col=N{col—;row+=2;}//〃行越界else if row0{row=N-l;}〃列越界else ifcol=N{col=0;}〃有冲突else ifresult[row][col]!=0{col—;row+=2;}〃打印出九宫格for inti=0;iN;i++{forint j=0;jN;j++{System.out.printresult[i][j]+n\tn;}System.out.println;//我个人的填格方式//为免冲突,重新一个数组int[][]result2=new int[N][N];new〃先把中间值给予中间位置result2[N/2][N/2]=N*N+l/2;〃定义行及列的初始赋值位置之前赋值的对两个值有影响,故需row=0;for重新定位col=N/2;for inti=l;i=N*N/2;i++{result2[row]|col]=i;〃下面这句是把跟对应的值放到格局对应的位置上iresult2[N-row-1][N-col-1]=N*N+l-i;row—;col++;〃行越界ifrow0{row=N-l;}〃列越界else ifcol=N{col=0;}//有冲突else ifresult2[row][col]!=0{col—;row+=2;}〃这方法不行能出现行列两边都越界的状况,详情须要数学论证System.out.println;〃再次打印出九宫格,以对比验证for inti=0;iN;i++{forint j=0;jN;j++{System.out.printresult2[i][j]+n\tn;}System.out.println;}求一个矩阵对角线元素之和9,3*3打印杨辉三角10,约梭芬杀人法
11.把犯人围成一圈,每次从固定位置起先算起,杀掉第个人,直到剩下最终一个7用数组实现约瑟夫出圈问题个人排成一圈,从第一个人起先报数,从起先报,报到11_2,n1m的人出圈,剩下的人接着起先从报数,直到全部的人都出圈为止对于给定的求出全部1n,m,人的出圈依次推断随机整数是否是素数
12.产生个之间的随机整数,然后推断这个随机整数哪些是素数,哪些不是1000-999100public classPrimeTest{public staticvoid mainStringargs[]{forint i=0;i100;i++{int num=intMath.random*1000;PrimeTest t=new PrimeTest;ift.isPrimenum{System.out.printlnnum+n是素数!;}else{System.out.printlnnum+n不是素数!;System.out.println;public booleanisPrimeint num{forinti=2;i=num/2;i++{ifnum%i==0{第一个被整除!”;System.out.printlnnum+”“+i+return false;return true;冒泡排序法〃按从大到小的排序int tmp=a
[0];for inti=0;ia.length;i++{for intj=0;ja.length-i-1;j++{tmp=a[j];a[j]=a[j4-l];a[j+l]=tmp;练习day06某公司的雇员分为以下若干类这是全部员工总的父类,属性员工的姓名和生日月份Employee方法依据参数月份来确定工资,假如该月员工过生日,则公司会额外嘉奖getSalaryint month元100的子类,拿固定工资的员工属性月薪SalariedEmployeeEmployee的子类,按小时拿工资的员工,每月工作超出HourlyEmployeeEmployee160小时的部分依据倍工资发放1・5属性每小时的工资、每月工作的小时数的子类,销售人员,工资由月销售额和提成率确定SalesEmployeeEmployee属性月销售额、提成率的子类,有固定底薪的销售人员,BasePlusSalesEmployeeSalesEmployee工资由底薪加上销售提成部分属性底薪public class TestEmployee{public staticvoid mainString[]args{Employee[]es=new Employee
[5];赵君”,es
[0]=new Employee2;“宋婕es[l]=new SalariedEmployee,1,8000;“王超”,es
[2]=new HourlyEmployee5,10,300;“秋娥”,es
[3]=new SalesEmployee2,200000,
0.05;郭镒鸿“,es
[4]=new BaseSalarySalesEmployee1,1000000,
0.1,10000;〃本月为月int month=2;2宇宙集团月工资表”;”+month+”forint i=0;ies.length;i++{System.out.printlnes[i].getName+,,:,+es[i].getSalarymonth;class Employee{private String name;private int birth;public StringgetName{return name;public EmployeeString name,int birth{this.name=name;上this irth=birth;public doublegetSalaryint month{ifmonth==birth{return100;return0;class SalariedEmployee extends Employee{private double salary;public SalariedEmployeeString name,int birth,doublesalary{supername,birth;this.salary=salary;public doublegetSalaryint month{return salary+super.getSalarymonth;class HourlyEmployeeextends Employeeprivate double hourSalary;private int hour;public HourlyEmployeeString name,int birth,double hourSalary,inthour{supername,birth;this.hourSalary=hourSalary;this.hour=hour;public doublegetSalaryint month{ifhour=160{return hourSalary*hour+super.getSalarymonth;}else{return160*hourSalary+hour-160*hourSalaryK
1.5+super.getSalary month;class SalesEmployeeextends Employee{private double sales;private double pre;public SalesEmployeeString name,int birth,double sales,double pre{supername,birth;this.sales=sales;this.pre=pre;public doublegetSalaryint month{return sales*pre+super.getSalarymonth;}class BaseSalarySalesEmployeeextends SalesEmployee{private double baseSalary;public BaseSalarySalesEmployeeStringname,int birth,doublesales,doublepre,doublebaseSalary{supername,birth,sales,pre;this.baseSalary=baseSalary;public doublegetSalaryint month{return baseSalary+super.getSalarymonth;/**在原有的雇员练习上修改代码公司会给每月另外发放元加班费,给SalaryEmployee2000发放元加班费BasePlusSalesEmployee1000改写原有代码,加入以上的逻辑并写一个方法,打印出本月公司总共发放了多少加班费@author Administrator*/public class EmployeeTest{/***@param args*/public staticvoid mainString[]args{Employeee[]=new Employee
[4];魏威e
[0]=new SalariedEmployee”[0,5000;丫£丫段利峰”,e[l J=new10111111^100©“8,80,242;“林龙e
[2]=new SalesEmployee”,11,300000,
0.1;e
[3]=new BasedPlusSalesEmployeen^M\1,100000,
0.15,1500;forint i=O;ie.length;i++{System.out.printlne[i].getName+n:,+e[i].getSalaryl1;}〃统计加班费int result=0;//forint i=O;ie.length;i++{//ife[i]instanceof SalariedEmployee{//SalariedEmployee s=SalariedEmployeee[i];//result+=s.getAddtionalSalaryO;////ife[i]instanceof BasedPlusSalesEmployee{//BasedPlusSalesEmployee b=BasedPlusSalesEmployeee[i];二//result+b.getAddtionalSalary;//}//forint i=0;ie.length;i++{result+=e[i].getAddtionalSalary;加班费result;interface AddtionalSalary{int getAddtionalSalaryO;classEmployeeimplements AddtionalSalary{〃员工姓名private Stringname;〃员工生日月份private int birth;public EmployeeStringname,int birth{this.name=name;thiibirth=birth;public intgetSalaryint month{int result=0;ifmonth=birthresult=100;return result;public StringgetName{return name;public intgetAddtionalSalaryO{return0;}}class SalariedEmployeeextends Employee{private int salary PerMonth;public SalariedEmployeeStringname,int birth,int salary PerMonth{supername,birth;this.salaryPerMonth=salaryPerMonth;public intgetSalaryint month{return this.salaryPerMonth+super.getSalarymonth+this.getAddtionalSalaryO;public intgetAddtionalSalaryO{return2000;class HourlyEmployeeextends Employee{private intsalaryPerHour;private inthoursPerMonth;public HourlyEmployeeStringname,int birth,intsal ary PerHour,i nthoursPerMonth{supername,birth;this.salaryPerHour=salaryPerHour;this.hoursPerMonth=hoursPerMonth;public intgetSalaryint month{int result=0;ifthis.hoursPerMonth=160{result=hoursPerMonth^salaryPerHour;}else{result=160*salaryPerHour+inthoursPerMonth-160*
1.5*salary PerHour;}return result+super.getSalarymonth;class SalesEmployeeextends Employee{private int sales;privatedouble rate;public SalesEmployeeStringname,intbirth,int sales,double rate{supername,birth;this.sales=sales;二this.rate rate;public intgetSalaryint month{return intsales*rate+super.getSalarymonth;class BasedPlusSalesEmployeeextends SalesEmployee{private intbasedSalary;public BasedPlusSalesEmployeeStringname,intbirth,intsales,doublerate,intbasedSalary{supername,birth,sales,rate;this.basedSalary=basedSalary;public intgetSalaryint month{return this.basedSalary4-super.getSalarymonth+this.getAddtionalSalary;}public intgetAddtionalSalaryO{return1000;经典算法某学校为学生安排宿舍,每个人一间房不考虑性别差异,问须要多少房答案
1.6x+5/6留意理解血类型数值让数值在之间循环
2.〜9public classtest{public staticvoid mainString||args{inti=0;whiletrue{i=i+l%10;System.out.printlni;作业写一个数组类放对象
1.功能包括添加添加不限制多少项、修改、插入、删除、查询class MyArray{private Object[]os=new Object
[10];public voidaddObject o;public voidsetint index,Object o;public voidinsertint index,Objecto;public voidremoveint index;public voidremoveObject o;public Objectgetint index;public classTestMyArray{public staticvoid mainString[]args{MyArray ma=new MyArray;ma.addHaaa;ma.addnbbbn;ma.addncccn;Object o=ma.getl;Iterator it=ma.iterator;whileit.hasNext{Object ol=it.next;System.out.printlnol;作业10-08随机产生个整数(以内的),放入一个中,用迭代器遍历这个
1.201ArrayList ArrayList并删除其中为的数
2.5再产生个整数,插入到位置处
3.34把全部值为的数都变成
4.110import java.util.ArrayList;/*利用构造进行实例化*/public Jsq{计算器frame=new JFramejtx=new JTextField14;bus=new JButton
[16];strs=789/456*123-
0.+=”.toCharArray;for inti=0;i16;i++{bus[i]=new JButtonstrs[i]+”;bus[i].add ActionListenerthis;bu=new JButton“C”;bu.addActionListenerthis;init;初始化*//*GUIpublic voidinit{JPanel jpl=new JPanel;jpl.addjtx;jpl.addbu;frame.addjp1,BorderLayout.NORTH;JPanel jp2=new JPanel;jp
2.setLayoutnew GridLayout4,4;forinti=0;i16;i++{jp
2.addbus[i];frame.addjp2,BorderLayout.CENTER;frame.pack;frame.setLocation300,400;frame.setVisibletrue;frame.setDefaultCloseOperationJFrame.EXIT_ON_CLOSE;/*事务的处理*/public voidactionPerformedActionEvent argO{/*获得输入字符*/String conn=arg
0.getActionCommand;/*清除计算器内容*/if nCn.equalsconn{class ArrayList{private Object[]os=new Object
[20];public classTest Array{public staticvoid mainString[]args{ArrayList a=new ArrayList;ma.addnaaan;ma.addnbbbn;ma.addnccc;二Object oma.getl;Iterator it=ma.iterator;whileit.hasNext{Object ol=it.next;System.out.printlno1;产生个以内的数,放入
1.300010hashSet遍历它,打印每一个值
2.import java.util.HashSet;import java.util.Iterator;import java.util.Random;public classTestHashSet{public staticvoid mainStringf]args{Random r=new Random;HashSet hsl=new HashSet;forint i=0;i3000;i++{hs l.addr.nextlntl0;Iterator itl=hsl.iterator;whileit
1.hasNext{System.out.printitl.next+n n;//由于不能重复,所以只有个数在里面,按哈希排序HashSet102498613750*测试的比较器,TreeSet*在有自己的比较器的状况下,如何实现接口*/Comparableimport java.util.*;class Teacher{int id;Stringname;int age;public Teacher{}public Teacherint id,Stringname,int age{this.id=id;this.name=name;this.age=age;public intgetld{return id;}public voidsetldint id{this.id=id;}public StringgetName{returnname;}public voidsetNameString name{this.name=name;}public intgetAge{return age;}public voidsetAgeint age{this.age=age;}public intTeacherComparatorObject o{Teacher tl=Teacher o;iftl.getldid{return1;}else iftl.getldQid{return-1;}return0;class TreeSet{}classTest{public staticvoid mainString[]args{String si=new Stringnaaan;String s2=new Stringnbbbn;Strings3=new StringHaaan;System.out.printlns1==s3;System.out.printlns
1.equalss3;HashSet hs=new HashSet;hs.addsl;hs.adds2;hs.adds3;Iterator it=hs.iterator;whileit.hasNext{System.out.printlnit.next;System.out.printfn%x\nH,s l.hashCode;System.out.printfM%x\nn,s
2.hashCode;System.out.printfn%x\nH,s
3.hashCode;在中,以作以类作写一个
1.Map nameKey,Student Velue,HashMap import java.util.*;classStudent{int id;Stringname;int age;public Student{}public Studentintid,Stringname,int age{this.id=id;this.name=name;this.age=age;public intgetld{return id;}public voidsetldint id{this.id=id;}public StringgetName{return name;}public voidsetNameString name{this.name=name;}public intgetAge{return age;}public voidsetAgeint age{this.age=age;}class TestHashMap{public staticvoid mainString[]args{叩;HashMap hm=new HashM二Student sinew Student1/jacky19;hm.put,jackyn,sl;hm.putHtomn,new Student2,tomn,21;hm.putHkittyH,new Student3,nkittyn,17;Iterator it=hm.keySet.iterator;whileit.hasNext{Object key=it.next;Student value=Student hm.getkey;System.out.printlnkey4-n:id=n4-value.id4-n,age=n+value.age;System.out.println,=============================n;//比较和两种迭代方式KeySet entrySetforIteratoril=hm.entrySet.iterator;il.hasNext;叩;{Map.Entry me=M.Entry il.nextStudent s=Student me.getValue;System.out.printlnme.getKey+n:id=+s.id+age=n+s.age;}day13homework/7*7*7*7*7*7*7^2*7*7*7*7**1*7**1*7*7*7*7*7*7*7*7^77*7*7^2*7*7*7*7*7**1*7*7*7*7**1*7*7*7**£*7*7/.卜.卜V、*7*1*,卜V、*1*,I、卜V、7*,卜
1.卜〃、.卜,卜〃、7^’卜,卜1〃、^7*^1*.卜,I、.[、*1*V、〃、*1*,卜,】、〃、
1.卜d、〃、
4、,
1、■】、〃、****自己写一个栈(先进后出)建议底层用实现LinkedList方法测试堆栈是否为空boolean empty查看栈顶对象而不移除它E peek移除栈顶对象并作为此函数的值返回该对象E pop把项压入栈顶E pushEitem返回对象在栈中的位置,以为基数int searchObject o1*£**1*7,7,*1**1**L*7,7,*1*7,7,*1**1**1*K!*1*7,*1*KJ**L*7,*1**1**.!KJ*7,7,*1**1**L*KI*K!***7,7,*1**1**L*7,7,*1**1*7,*1**1**1**1**L*KI*7,*1**1*,j.q.,j、—j*q.,j、*4*q./j.-j、q.,j、*2**4*t、*4*4*i、■
1、*1**4*,|、1*q*,j.-j./j**2*4**4**4*-j*〃不能用继承,因为它破坏封装只需调用即可import java.util.LinkedList;class MyStackE{private LinkedListElist=new LinkedListE;public booleanempty{return list.isEmptyQ;}public Epeek{return list.peek;}public voidpushE o{list.addFirsto;}public Epop{return list.poll;}返回此列表中首次出现的指定元素的索引,假如此列表中不包含该元//int indexOfObjecto素,则返回-1public intsearchObjecto{return list.indexOfo;}/7,7,*1**1**4**1*7,7,*1**4**1**1*7,7,■1**1**1**1*7,7,*1**1**1**1*K17,*1**1**1**1*7,7,*1**1**1**1*KI
7.7,■!*-1**1*K1KF!7,♦!****K£*KI7,7,*1**1*7,7,*1**1**1**1**L*7,7,■1**1**1**f*!*7,*1*/q、J、q.q.
4、ry»〃、
1、rj**4*q.q、q、rj*q.〃、q.
4、rj*q、rj*q.—、*j**2**7*q.〃、
4、****y*
4、、rj*q.q、J、*2**1**1*7,7,7,41*K|K|*|*〃、〃、定义以下类,完成后面的问题,并验证类考试类Exam属性若干学生一张考卷提示学生采纳存放HashSet类考卷类Paper属性若干试题Student类学生类属性姓名一张答卷一张考卷考试成果Question类试题类属性题号题目描述若干选项正确答案提示试题采纳存放,为表示题号,为试题对象HashMap keyString,value提示若干选项用ArrayList类答卷类AnswerSheet属性每道题的答案提示答卷中每道题的答案用存放,为表示题号,为学生的答案问题HashMap keyString,value为类添加一个方法,用来为全部学生判卷,并打印成果排名名次、姓名、成果Exam*£**1*7,7,*1**1*7,7,*1*7,7,*1**1**1**1*7,*1*KJ**L*7,*1**1**.!KJ*7,7,*1**1**L*KI*K!***7,7,*1**1**L*7,7,*1**1*7,*1**1**1**1**L*KI*7,*1**1*,j.q.,j、—j*q.,j、*4*q./j.-j、q.,j、*2**4*t、*4*4*i、■
1、*1**1**4*q*q、,|、1*q*,j.-j./j**2*4**4**4*-j*/K**!**1**!**1^KJf*!*!*KJ K|*KJ*K|*!**!**!^K|KF*K|*K|*KL»K|K!*K!*f*KJ*KJ K|1K!*K|^K|K|1KL*K|**!/*T**T**T**j**T**T**l**7**T**T^*T^*T**T^*T^*T**7**T**T**T**T**T**7**T**T**1**T**T»*T**7**7**T**T^*T**T**7**T**T^*T**T**j**7**T**T^*T^*7^*7**7**T»*T^*T**T**1*■】,L*■],■],*1;**.1**1**],*T**T**T**Tw*7**T»*T*项目商品管理系统功能增删改查(可按各种属性查)商品属性名称、价格(两位小数)、种类*1**1**1*1*!**L»*t**1*t•1*!*■的1*£*1*L»*1**1**1*•!**!*■的•1*•!**!**1*•1*1**1•1**!•*1**1**!*T**T**T*^T**T**T**T**T^*T**T**T**T**T**T**T^*T**T**T**T**T**T**T**T**T**T**T**T**T**T**T**T**T**T**T**T**T**T**T**T**T**T**T**T**T**T**T**T**T»*T^*T**T**T**T»*T**T**T**T**T**T»*T**T**T**T**T**1**1**1*■!**1*■*1*/T*rrwTw*J.*J..].7*T*/图形界面day17计算器
1./*****************例题画出计算器的界面*1**1**1**1^K1*KJ**!**!^*!**!**!**1^KL»*1**1**!**1^*T**T**T^*T**7**T**T**T**T**T^*T**T**T**T^*T**T**Tw*T*界面如下123456-789*
0.=/*1*/•卜•卜•卜・卜一]••.••,、•卜•卜•[•一[•,.,•.、•卜•卜•卜♦卜一,/import java.awt.*;import javax.swing.*;class Calculator{public staticvoid mainString||args{JTextField text=new JTextField;计算器JFramef=new JFrame“宋体”,宋体”想写成默认,则写Font font=new FontFont.BOLD,25;//““null”定义字体令的文字text.setFontfont;//text.setHorizontalAlignmentJTextField.RIGHT;//text从右边起设置文本不行修改,默认可修改text.setEditablefalse;//true f.addtext,和的默认布局管理器是BorderLayout.NORTH;//Frame DialogBorder LayoutButton Ac〃事务反应在中tionListener listener=new ButtonActionListenertext;text JPanel buttonPanel〃设法把计算器键盘放到这个按钮上=new JPanel;Jpanel Stringop=123+456-789*
0.=/;GridLayout gridlayout=new GridLayout4,4,10,10;〃把计算器键盘放到按钮上buttonPanel.setLayoutgridlayout;buttonPanel forint i=0;iop.length;i++{〃拿至字符串的第个字符char c=op.charAt⑴;lj i把字符放到按钮上在按钮JButtonb=new JButtonc+””;//b.addActionListenerlistener;//上放置监听器,每次按都会有反应〃把按钮放至上buttonPanel.addb;U buttonPanel}〃这个循环很值得学习,很常用〃默认添加到位置f.addbuttonPanel/*,BorderLayout.CENTER^/;CENTERf.setDefaultCloseOperationJFrame.EXIT_ON_CLOSE;f.setSize300,250;这句要放到最终,等事务完成后再显示f.setVisibletnie;//}〃监听者class ButtonActionListenerimplementsActionListener{private JTextFieldtextField;public ButtonActionListenerJTextFieldtextField{this.textField=textField;}{〃必需覆盖它的public voidactionPerformedActionEvent eactionPerformed哈哈,放了几个字textField.append\n;}}/*********************土京HU;4笆•奥羊幺0T力台匕*******************************/.扫雷嬉戏2•俄罗斯方块3多线程day19写两个线程,一个线程打印另一个线程打印字母打印依次为1〜52,A-Zo12A34B56C・・・・・・5152Z要求用线程间的通信注分别给两个对象构造一个对象数字每打印两个或字母每打印一个就执行o,o.waitQo在之前不要忘了写o.wait o.notifyQoclass Test{public staticvoid mainString[]args{Printer p=new Printer;Thread tl=new NumberPrinterp;Thread t2=new LetterPrinterp;tl.start;t
2.start;class Printer{设为便利计算的倍数private intindex=1;//1,3〃打印数字的构造方法,每打印两个数字,等待打印一个字母public synchronizedvoidprintinti{whileindex%3==0{try{wait;}catchException e{}}System.out.printn n+i;index++;notifyAHQ;//打印字母,每打印一个字母,等待打印两个数字public synchronizedvoid printcharc{whileindex%3!=0{try{wait;}catchException e{}}System.out.printn n+c;index++;notifyAll;〃打印数字的线程class NumberPrinterextends Thread{private Printerp;public NumberPrinterPrinterp{this.p=p;}public voidrun{forint i=1;i=52;i++{p.printi;〃打印字母的线程class LetterPrinterextends Thread{private Printerp;public LetterPrinterPrinterp{this.p=p;}public voidrun{forchar c=A;c=Z;c++{p.printc;/*假如这题中,想保存须要打印的结果,可在类里定义一个成员变量不写”Printer Strings”;//的话是跟没有东西是不一样的,它会把当成字符=_=然后在两个方法里面,null,null nullprint循环后分别加上以及while s=s+”+i;s=s++c;*/d_one=””;operator=”;jtx.setTextnn;return;/*暂未实现该功能*/ifH.n.equalsconn{return;/*记录运算符,保存运算数字*/if H+-*/n.indexOfconn!=-1{if,n.equalsd_onen.equalsjtx.getText return;d_one=jtx.getText;operator=conn;jtx.setTextnn;return;/*计算结果*/ifn=,,.equalsconn{if,n.equalsd_onen.equalsjtx.getText return;double db=0;ifn+n.equalsoperator{db=Double.parseDoubled_one+Double.parseDoublejtx.getText;jtx.setTextdb+”;ifn-n.equalsoperator{db=Double.parseDoubled_one-Double.parseDoublejtx.getText;jtx.setTextdb+”;if H*M.equalsoperator{db=Double.parseDoubled_one*Double.parseDoublejtx.getText;jtx.setTextdb+”;ifn/n.equalsoperator{二db Double.parseDoubled_one/Double.parseDoublejtx.getText;jtx.setTextdb+d_one=db+””;return;〃界面显示jtx.setTextjtx.getText+conn;三角形图案6package pm;public classSwitchTest{public staticvoid mainString[]args{intn=5;forinti=0;iv=n;i++{forint j=O;jn-i;j++{System.out.printnn;forint k=0;k2*i-1;k++{System.out.prinK*;}System.out.println;}输出输入的姓名7package pm;importjava.util.Scanner;public classSwitchTest{publicstaticvoid mainString[]args{二Stringnamenull;二Scanner seanew ScannerSystem.in;char firstChar;do{System.out.printlnplease inputyour name;name=sca.nextLine;firstChar=name.charAtO;}while!firstChar=,afirstChar=,z,||〈=firstChar=AfirstChar Z;System.out.printlnnOK!your nameis:n+name;一小时倒计时小程序8package pm;import javax.swing.JFrame;import javax.swing.JLabel;import javax.swing.JPanel;public classSwitchTest{private JFrameframe;private JLabeljll;private JLabeljl2;private JLabeljl3;/*主方法*/publicstaticvoid mainString[]args{new SwitchTest.getTime;}/*倒计时的主要代码块*/private voidgetTime{long time=1*3600;long hour=0;long minute=0;long seconds=0;whiletime=0{hour=time/3600;minute=time-hour*3600/60;二seconds time-hour*3600-minute*60;时;jlLsetTexthour+分”;jl
2.setTextminute+秒;jl
3.setTextseconds+try Thread.sleepl000;}catch InterruptedExceptione{e.printStackTrace;time—;/*构造实现界面的开发GUI*/public SwitchTest{倒计时frame=new JFramejll=new JLabel;jl2=new JLabel;jl3=new JLabel;init;/*组件的装配*/private voidinit{JPanel jp=new JPanel;jp.addjll;jp.addjl2;jp.addjl3;frame.addjp;frame.setVisibletrue;frame.setLocation300,400;frame.setSize300,200;frame.setDefaultCloseOperationJFrame.EXIT_ON_CLOSE;棋盘图案9publicclassSjx{。