欢迎来到天天文库
浏览记录
ID:22627094
大小:419.76 KB
页数:15页
时间:2018-10-30
《二级Java操作题.docx》由会员上传分享,免费在线阅读,更多相关内容在学术论文-天天文库。
1、第1套基本操作题importjavax.swing.JOptionPane;publicclassjava1{publicstaticvoidmain(String[]args){intx,y,z,result;StringxVal,yVal,zVal;xVal=JOptionPane.showInputDialog("输入第1个整数");yVal=JOptionPane.showInputDialog("输入第2个整数");zVal=JOptionPane.showInputDialog("输入第3个整数");x
2、=Integer.parseInt(xVal);y=Integer.parseInt(yVal);z=Integer.parseInt(zVal);result=x*y*z;JOptionPane.showMessageDialog(null,"三个整数之积是"+result);System.exit(0);}}15/15简单应用题importjavax.swing.*;publicclassjava2{publicstaticvoidmain(String[]args){StringBufferbur=newSt
3、ringBuffer("你好!祝你成功!");Stringoutput="buf="+bur.toString()+"Characterat0:"+bur.charAt(0)+"Characterat4:"+bur.charAt(4);charcharArray[]=newchar[bur.length()];bur.getChars(0,bur.length(),charArray,0);output+="在字符串缓存中的字符是:";for(inti=0;i4、+){output+=charArray[i];}bur.setCharAt(0,'您');bur.setCharAt(6,'材');output+="buf="+bur.toString();bur.reverse();output+="buf="+bur.toString();JOptionPane.showMessageDialog(null,output,"字符串缓存的字符相关方法示范",JOptionPane.INFORMATION_MESSAGE);System.exit(0);}}15/15综5、合应用题importjava.util.*;publicclassjava3{privateStringcolors[]={"红","白","蓝","黑","黄","紫","茶色","粉红"};privateArrayListaList;//ArrayList引用publicjava3(){aList=newArrayList(Arrays.asList(colors));Collections.sort(aList);//ArrayList分类System.out.println("对ArrayList分类:"+6、aList);}publicstaticvoidmain(String[]args){newjava3().printSearchResults();}publicvoidprintSearchResults(){printSearchResultsHelper(colors[3]);//首项printSearchResultsHelper(colors[0]);//中间项printSearchResultsHelper(colors[7]);//最后项printSearchResultsHelper("绿");/7、/最低printSearchResultsHelper("灰");//不存在printSearchResultsHelper("橙色");//不存在}privatevoidprintSearchResultsHelper(Stringkey){intresult=0;System.out.println("检索关键字:"+key);result=Collections.binarySearch(aList,key);System.out.println((result>=0?"找到下标"+result:"没有找到(8、"+result+")"));}}15/15第2套基本操作题package真题第2套;publicclassjava1{publicstaticvoidmain(String[]args){System.out.println("欢迎你参加Java考试");}}15/15简单应用题package真题第2套;publicclassjava2{p
4、+){output+=charArray[i];}bur.setCharAt(0,'您');bur.setCharAt(6,'材');output+="buf="+bur.toString();bur.reverse();output+="buf="+bur.toString();JOptionPane.showMessageDialog(null,output,"字符串缓存的字符相关方法示范",JOptionPane.INFORMATION_MESSAGE);System.exit(0);}}15/15综
5、合应用题importjava.util.*;publicclassjava3{privateStringcolors[]={"红","白","蓝","黑","黄","紫","茶色","粉红"};privateArrayListaList;//ArrayList引用publicjava3(){aList=newArrayList(Arrays.asList(colors));Collections.sort(aList);//ArrayList分类System.out.println("对ArrayList分类:"+
6、aList);}publicstaticvoidmain(String[]args){newjava3().printSearchResults();}publicvoidprintSearchResults(){printSearchResultsHelper(colors[3]);//首项printSearchResultsHelper(colors[0]);//中间项printSearchResultsHelper(colors[7]);//最后项printSearchResultsHelper("绿");/
7、/最低printSearchResultsHelper("灰");//不存在printSearchResultsHelper("橙色");//不存在}privatevoidprintSearchResultsHelper(Stringkey){intresult=0;System.out.println("检索关键字:"+key);result=Collections.binarySearch(aList,key);System.out.println((result>=0?"找到下标"+result:"没有找到(
8、"+result+")"));}}15/15第2套基本操作题package真题第2套;publicclassjava1{publicstaticvoidmain(String[]args){System.out.println("欢迎你参加Java考试");}}15/15简单应用题package真题第2套;publicclassjava2{p
此文档下载收益归作者所有