ACCP3.0 Java编程基础.课后练习题

2004年11月4日
P43 t1
public class test{
 public static void main(String[] args){
  for(int i=4;i>0;i--){
   for(int j=0;j<i;j++){
    System.out.print("1");
    }
   System.out.println();
   }
  }
 }


P43 t2
import java.util.*;
public class test{
 public static void main(String[] args){
  int[] intarray={2,5,8,4,6};
  Arrays.sort(intarray);//进行数组排序
  System.out.println("Max is "+intarray[4]);
  System.out.println("Min is "+intarray[0]);
 }
}

P72 t3
class fulei{
 void fulei(int age,String name){
  System.out.println(name+"'s age is "+age);
  }
 }
public class test extends fulei{
 public static void main(String[] ages){
  fulei m=new test();//这里还有点不明白
  m.fulei(20,"lile");
  }
 }

2004年11月5日
P93 t2
/*
 * 创建日期 2004-11-5
 *^_^用eclipse做的.偷懒了
 */

/**
 * @author lileltp
 *
 * TODO 要更改此生成的类型注释的模板,请转至
 * 窗口 - 首选项 - Java - 代码样式 - 代码模板
 */
interface Vehicle{
    void Start(int x);
    void Stop(int y);
}
class Bus implements Vehicle{

    /* (非 Javadoc)
     * @see Vehicle#Start(int)
     */
    public void Start(int x) {
        // TODO 自动生成方法存根
       
    }

    /* (非 Javadoc)
     * @see Vehicle#Stop(int)
     */
    public void Stop(int y) {
        // TODO 自动生成方法存根
       
    }
   
}
class Bike implements Vehicle{

    /* (非 Javadoc)
     * @see Vehicle#Start(int)
     */
    public void Start(int x) {
        // TODO 自动生成方法存根
        System.out.println("这个是bike的方法Start "+x);
    }

    /* (非 Javadoc)
     * @see Vehicle#Stop(int)
     */
    public void Stop(int y) {
        // TODO 自动生成方法存根
       
    }
   
}
public class interfaceDemo {

    public static void main(String[] args) {
        Bike a=new Bike();
        a.Start(5);
    }
}

P109 t1,2
/*
 * 创建日期 2004-11-5
 * 判断输入是否为byte类型.
 */

/**
 * @author lileltp
 *
 */
import javax.swing.JOptionPane;
public class CheckByte {
    void CheckByteDemo(String s){
        try{   
        byte b=Byte.parseByte(s);//转换成byte类型,如果不成功抛出异常
     System.out.println("This is Byte.");
        }catch(NumberFormatException e){
            System.out.println("You input is not byte");
        }
    }
    public static void main(String[] args) throws ByteSizeException {
        String s=JOptionPane.showInputDialog("Please input");
        CheckByte demo=new CheckByte();
        demo.CheckByteDemo(s);

    }
class ByteSizeException extends Exception{
    public ByteSizeException(){
        super();
    }
}
   
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值