java试卷20

public class Java_1 {
    public static void main(String[] args) {
        //*********Found********
        int []f= new int[10];
        f[0]=f[1]=1;
        //*********Found********
        for (int i = 2;i<10;i++)
            f[i]=f[i-1]+f[i-2];
        //*********Found********
        for (int i=0;i<f.length;i++)
        //*********Found********
            System.out.print(f[i]+"  ");
    }
    
}



public class Java_2{
   public static void main(String[] args){
      //*********Found**********
      int [][] aMatrix = new int[4][];
      int i = 0;
      int j = 0;
      int k = 4;

      for(i = 0; i < 4; i++){
         //*********Found**********
         aMatrix[i] = new int[k--];
 
         //*********Found**********
         for (j = 0; j < aMatrix[i].length; j++) {
            aMatrix[i][j] = i+1;
            System.out.print(aMatrix[i][j] + " ");
         }
         //*********Found**********
         System.out.println();
      }
   }
}

//打印无符号整数位
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

public class Java_3 extends JFrame {
   public Java_3(){
      super( "打印无符号整数位" );
      Container c = getContentPane();
      c.setLayout( new FlowLayout() );
      c.add( new JLabel( "请输入整数: " ) );
      final JTextField output = new JTextField( 33 );
      JTextField input = new JTextField( 10 );
      input.addActionListener(
         new ActionListener() {
            //*********Found********
            public void actionPerformed( ActionEvent e ){
               int val = Integer.parseInt(
                  e.getActionCommand() );
               //*********Found********
               output.setText( getBits( val ) );
            }
         }
      );
      c.add( input );
      c.add( new JLabel( "该数的二进制位表示是" ) );      
      output.setEditable( false );
     //*********Found********
      c.add( output );
      setSize( 720, 70 );
      setVisible(true);
   }

   private String getBits( int value ){
      int displayMask = 1 << 31;
      StringBuffer buf = new StringBuffer( 35 );
      for ( int c = 1; c <= 32; c++ ) {
         buf.append(
            ( value & displayMask ) == 0 ? '0' : '1' );
         value <<= 1;
         if ( c % 8 == 0 )
            buf.append( ' ' );
      }
      return buf.toString();
   }

   public static void main( String args[] ){
      Java_3 app = new Java_3();
      app.addWindowListener(
         new WindowAdapter() {
     //*********Found********
            public void windowClosing( WindowEvent e ){
               System.exit( 0 );
            }
         }
      );
   }
}

猜你喜欢

转载自blog.csdn.net/qq_38640439/article/details/82349100