晕,作业题吧,找同学的copy一份吧

解决方案 »

  1.   

    晕,作业题吧,找同学的copy一份吧
      

  2.   

    2.public class Assignment2{
      private static final int TIMES = 6000;
      public static void main(String[] args){
        int[] numbers = new int[TIMES];
        java.util.Random r = new java.util.Random();
        for(int i = 0; i < TIMES; i++){
          numbers[i] = r.nextInt(6) + 1;
          System.out.print(numbers[i] + " ");
        }
      }
    }
      

  3.   

    " 晕,作业题吧,找同学的copy一份吧 "........@_@!
      

  4.   

    1.//<applet code="Assignment1.class" width="400" height="300">
    //</applet>
    import javax.swing.*;
    import java.awt.event.*;
    import java.awt.*;public class Assignment1 extends JApplet{
      private JTextField time;
      private JButton charge;
      private JLabel label;
      public void init(){
        Container cp = getContentPane();
        cp.setLayout(new FlowLayout());
        
        time = new JTextField(10);
        cp.add(time);
        
        charge = new JButton("Charge");
        cp.add(charge);
        charge.addActionListener(new ActionListener(){
                                 public void actionPerformed(ActionEvent e){
                                   try{
                                    double tm = Double.parseDouble(time.getText());
                                    label.setText("It should charge: " + getCharge(tm));
                                   }catch(NumberFormatException nfe){
                                     JOptionPane.showMessageDialog(null,"Bad number format","error",JOptionPane.ERROR_MESSAGE);
                                   }catch(TimeTooLongException ttlf){
                                     JOptionPane.showMessageDialog(null,ttlf.getMessage(),"error",JOptionPane.ERROR_MESSAGE);
                                   }
                                 }
                              });
        
        label = new JLabel();
        cp.add(label);  
      }
      
      private double getCharge(double tm) throws TimeTooLongException{
         if(tm <= 0) return 0;
         if(tm <= 3)
             return 2;
         if(tm == 24) return 10;
         if(tm < 24){
           if((tm - (int)tm) > 0)
             tm++;
           return 2 + (Math.floor(tm) - 3) * 0.5;
           }
         throw new TimeTooLongException("Time cannot greater than 24");
      }
    }class TimeTooLongException extends Exception{
      public TimeTooLongException(){}
      public TimeTooLongException(String msg){
        super(msg);
      }
    }
      

  5.   

    public class star
    {
    public static void main(String args[])
    {
      int i;
      int j,j1,j2;
      int t=9;
      j1=(t-1)/2;
      j2=(t-1)/2;
      for (i=0;i<=(t-1)/2;i++)
      {
      for (j=0;j<=(t-1)/2+i;j++ )
          {
          if (j<j1|j>j2)
             System.out.print(" ");
          else
         System.out.print("*");    
          }
          j1--;
          j2++;
      System.out.println();
      }
      j1=0;
      j2=t-1;
          for (i=(t+1)/2;i<t;i++)
      {
      j1++;
          j2--;
      for (j=0;j<=(t-1)/2+i;j++ )
          {
          if (j<j1|j>j2)
             System.out.print(" ");
          else
         System.out.print("*");    
          }
          
      System.out.println();
      }
    }
    };
      

  6.   

    public class PrintStar {
    public static void main(String[] args) {
    int layer = 6;
    String content="";
    int space=0;
    int star = 0;
    for(int i=0;i<2*layer-1;i++) {
    if (i<layer) {
    space=layer-i-1;
    star=2*i+1;
    }else {
    space=i-layer+1;
    //star=2*(2*layer-i-1)-1;
    star=4*layer-2*i-3;
    }
    for(int j=0;j<space;j++) 
    content+=" ";
    for(int j=0;j<star;j++)
        content+="*";
    System.out.println(content);
    content="";

    }
    }
    }