if(ch>='A'&&ch<='Z'||ch>='a'&&ch<='z') x++;
else if(ch>='0'&&ch<='9') y++; else z++; }
}catch(IOException e){
System.out.println(e.toString()); }
System.out.println(\英文字母:\System.out.println(\数字字符:\System.out.println(\其它字符:\} } 4.答:
import java.io.*; public class InFile{
public static void main(String[] args) { int ch; try{
FileOutputStream out=new FileOutputStream(\while((ch=System.in.read())!='\\r'){
System.out.write(ch); out.write(ch); }
out.close();
System.out.write('\\n'); }catch(IOException e){
System.out.println(e.toString()); }
System.out.println(\输出至文件完毕!\} } 5.答:
import java.io.*; public class Sort{
public static void main(String args[]) {
int a[]=new int[10]; byte b[]=new byte[10]; int t; String str;
System.out.println(\请输入10个整数:\try{
for(int i=0;i<10;i++)
{System.out.print(\System.in.read(b); str=new String(b); str=str.trim();
a[i]=Integer.parseInt(str); }
}catch(IOException e){
System.out.println(e.toString()); }
catch(NumberFormatException e){ System.out.println(e.toString()); }
for(int i=0;i<9;i++) for(int j=i+1;j<10;j++) {
if(a[i]>a[j]){ t=a[i]; a[i]=a[j]; a[j]=t; } }
for(int i=0;i<10;i++)
System.out.println(a[i]+\}
}
第八章:
1.编写一个Applet程序和相应的页面文件,通过页面文件传递参数,在Applet程序中绘制一个长方形(长方形的长度和宽度由页面文件传递)。
2.编写一个Applet程序,用来显示与Applet程序在同一文件夹下的图片文件“flower.jpg”。 3.编写一个Applet程序,用来循环播放与Applet程序在同一文件夹下的声音文件“sound.mid”,作为网页的背景音乐。
4 编写程序,实现如图所示功能:在x和y两个文本框中输入数值,按下右面的任意按钮能进行相应的计算,并将结果显示在中间的文本区中,该区域可以用清除按钮清除。(本题15分)
1.Applet代码如下: import java.awt.*; import java.applet.*;
public class ParameterSend extends Applet{ int length,width; public void init(){
length=Integer.parseInt(getParameter(\width=Integer.parseInt(getParameter(\}
public void paint(Graphics g){
g.setColor(Color.red);
g.drawRect(10,10,length,width); } }
HTML页面代码如下:
code= ParameterSend.class width = 280 height = 100>
2.Applet代码如下: import java.awt.*;
import java.applet.Applet;
public class ImageApplet extends Applet {
Image image; public void init()