java二级试卷33套

import java.io.*;

public class Java_1 {
  public static void main(String[] args) {
    char[] charArray = {'a','b','c','d','e','f','g','h','i'};
    char c  ;
    try{
//*********Found**********
        DataOutputStream out = new DataOutputStream(
               new FileOutputStream("test.dat"));
        for(int i =0; i<charArray.length; i++){
           out.writeChar(charArray[i]);
        }
        out.close();		
        DataInputStream in = new DataInputStream(
//*********Found**********
               new FileInputStream("test.dat"));
        while(in.available() != 0){
           c=in.readChar();
           System.out.print(c+" ");
        }
        System.out.println();
//*********Found**********
        in.close();
    }catch(IOException e){}
  }
}

 

 

//*********Found**********
import javax.swing.*;

public class Java_2{
  public static void main(String[] args){
//*********Found**********
    String input = JOptionPane.showInputDialog("你想抽几个数?");
    int k = Integer.parseInt(input);
    input = JOptionPane.showInputDialog("你想在自然数中抽的最大数是几?");
    int n = Integer.parseInt(input);
    int lotteryOdds = 1;
//*********Found**********
    for (int i = 1; i <= k; i++)
       lotteryOdds = lotteryOdds * (n - i + 1)/i;
//*********Found**********
    System.out.println("你中奖的几率是1/" + lotteryOdds + ". Good luck!");
    System.exit(0);
  }
}

 

 

 

import java.awt.*;
import javax.swing.*;

//*********Found**********
public class Java_3 extends JApplet{
   JTextArea outputArea;
   public void init(){
      outputArea = new JTextArea();
//*********Found**********
      Container c = getContentPane();
//*********Found**********
      c.add( outputArea );
      //计算0至10的阶乘
      for ( long i = 0; i <= 10; i++ )
         outputArea.append(
            i + "! = " + factorial( i ) + "\n" );
   }  
   //阶乘的递归定义
   public long factorial( long number ){                  
      if ( number <= 1 ) 
         return 1;
      else
         return number * factorial( number - 1 );
   }  
}

 

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值