自考Java语言程序设计一程序设计综合题汇总.pdf
《自考Java语言程序设计一程序设计综合题汇总.pdf》由会员分享,可在线阅读,更多相关《自考Java语言程序设计一程序设计综合题汇总.pdf(15页珍藏版)》请在淘文阁 - 分享文档赚钱的网站上搜索。
1、一、程序填空,阅读下列程序并完成程序填空1.用Java Applet小应用程序完成下列填空import java.applet.*;import java.applet.*;import java.import java.【awtawt】.*;.*;public class test1_1 extendspublic class test1_1 extends【AppletApplet】public void paint(public void paint(【GraphicsGraphics】g)g)int x=2,y=1;int x=2,y=1;【switchswitch】(x+y)(x+y
2、)case 1:case 1:g.setColor(Color.red);g.setColor(Color.red);g.drawString(“g.drawString(“我是红色”,5 5,10)10);break;break;case 2:case 2:g.setColor(Color.blue);g.setColor(Color.blue);g.drawString(“g.drawString(“我是蓝色”,5 5,10)10);break;break;case 3:case 3:g.setColor(Color.green);g.setColor(Color.green);g.dra
3、wString(“g.drawString(“我是绿色”,5 5,10)10);break;break;【default default】:g.drawString(“g.drawString(“没有设置颜色”,5 5,10)10);awt Applet Graphics switch default2.import java.import java.【appletapplet】.*;.*;import java.awt.*;import java.awt.*;public class test1_1public class test1_1【extendsextends】AppletApple
4、t public void paint(Graphics g)public void paint(Graphics g)int int【sum=0sum=0】;for(int i=1;for(int i=1;【i=100i=100】;i+);i+)sum=sum+i;sum=sum+i;g.g.【drawStringdrawString】(“sum=”+sum,10,20);(“sum=”+sum,10,20);applet extends sum=0 i=100 drawString applet extends sum=0 i=100 drawString3.【publicpublic】c
5、lass test1_1class test1_1 public public【staticstatic】void main(void main(【StringString】args)args)int i,j;int i,j;for(j=2;j=50;j+)for(j=2;j=50;j+)for(i=2;i=j/2;i+)for(i=2;ij/2)if(ij/2)System.System.【outout】.pritnln(j+”.pritnln(j+”是素数”);”);public static String j%i=0 out4.import java.import java.【apple
6、tapplet】.*;.*;import java.awt.*;import java.awt.*;【classclass】ChengjiChengji float f(float x,float y)float f(float x,float y)return x*y;return x*y;class Xiangjiaclass Xiangjia【extendsextends】ChengjiChengji float f(float x,float y)float f(float x,float y)return x+y;return x+y;public class test1_1 ext
7、ends Appletpublic class test1_1 extends Applet Xiangjia sum;Xiangjia sum;public void public void【init()init()】sum=new Xiangjia();sum=new Xiangjia();public void paint(public void paint(【GraphicsGraphics】g)g)g.drawString(“sum=”+sum.f(4,6),5,20);g.drawString(“sum=”+sum.f(4,6),5,20);applet class extends
8、 init()Graphics5.【classclass】StudentStudent int number;String name;int number;String name;【StudentStudent】(int number,String name)(int number,String name)this.number=number;this.name=name;this.number=number;this.name=name;Systemout.println(“I am”+name+”My number is”+number);Systemout.println(“I am”+
9、name+”My number is”+number);class Univer_Studentclass Univer_Student【extendsextends】StudentStudent boolean boolean 婚否;Univer_Student(int number,String name,boolean b)Univer_Student(int number,String name,boolean b)【supersuper】(number,name);(number,name);婚否=b;=b;System.out.pritnln(“System.out.pritnln
10、(“婚否=”+=”+婚否););public class test1_1public class test1_1 public static void main(String args)public static void main(String args)Univer_Student zhang=Univer_Student zhang=【newnew】Univer_Student(9901,”Univer_Student(9901,”和小林”,false);”,false);class Student extends super new6.import java.applet.*;impo
11、rt java.awt;import java.applet.*;import java.awt;class test1_extendsclass test1_extends【AppletApplet】【StringString】tom;tom;public voidpublic void【init()init()】tom=”2203026206209021”;tom=”2203026206209021”;public void paint(public void paint(【GraphicsGraphics】g)g)if(tom.if(tom.【startsWithstartsWith】(
12、“”220)&(“”220)&(tom.endsWith(“1”)|tom.endsWith(“3”)(tom.endsWith(“1”)|tom.endsWith(“3”)g.drawString(“tom g.drawString(“tom 是吉林人,男性”,10,10);”,10,10);Applet String init()Graphics statsWith7.import java.applet.*;import java.applet.*;import java.import java.【awtawt】.*;.*;public class test1_1 extendspubl
13、ic class test1_1 extends【AppletApplet】【String String】tom=”I am a good cat”;tom=”I am a good cat”;int x,y,z;int x,y,z;public void paint(Graphics g)public void paint(Graphics g)x=tom.x=tom.【indexOfindexOf】(“a”);y=tom.indexOf(“good”,2);z=tom.indexOf(“a”,7);(“a”);y=tom.indexOf(“good”,2);z=tom.indexOf(“a
14、”,7);g.g.【setColorsetColor】(Color.red);(Color.red);g.drawString(“”+x+”:”+y+”:”+z,20,20);g.drawString(“”+x+”:”+y+”:”+z,20,20);awt Applet String indexOf setColor8.【importimport】java.applet.*;java.applet.*;import java.awt.*;import java.awt.*;public class test1_1 extendspublic class test1_1 extends【Appl
15、et Applet】【TextFieldTextField】text1,text2;text1,text2;public void public void【init()init()】text1=new TextField(“text1=new TextField(“输入密码:”,10)10);text1.setEditable(false);text1.setEditable(false);text2=new TextField(10);text2=new TextField(10);text2.text2.【setEchoCharsetEchoChar】(*);(*);add(text1);
16、add(text2);add(text1);add(text2);import Applet TextField init()setEchoChar9.【importimport】java.applet.*;java.applet.*;import java.awt.*;import java.awt.*;public class test1_1 extendspublic class test1_1 extends【AppletApplet】【ButtonButton】button1,button2;button1,button2;public voidpublic void【init()i
17、nit()】button1=new Button();button1=new Button();button2=new Button(“button2=new Button(“确定”);”);【addadd】(button1);add(button2);(button1);add(button2);import Applet Button init()add10.import java.import java.【appletapplet】.*;.*;import java.awt.*;import java.awt.*;public class Test1_1 public class Tes
18、t1_1【extendsextends】AppletApplet 【LabelLabel】labe1;labe1;【TextField TextField】text1;text1;public void init()public void init()label1=new Label(“label1=new Label(“输入姓名”);”);label1.label1.【setBackgoundsetBackgound】(Color.red);(Color.red);text1=new TextField(10);text1=new TextField(10);add(label1);add(
19、text1);add(label1);add(text1);applet extends Label TextField setBackgroud11.import java.awt.*;import java.awt.*;import java.applet.*;import java.applet.*;public class test1_1public class test1_1【extendsextends】Applet Applet【panelpanel】p;p;【ScrollpaneScrollpane】scrollpane;scrollpane;public void publi
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 自考 Java 语言程序设计 程序设计 综合 汇总
限制150内