日期:2014-05-20 浏览次数:20803 次
double pi = 3.1415926535897932384; //System.out.println(pi); float f = (float)pi; //System.out.println(f); String sd = Long.toBinaryString(Double.doubleToLongBits(pi)); System.out.printf("%64s\n", sd); System.out.printf("%64s\n", sd.substring(12)); String sf = Integer.toBinaryString(Float.floatToIntBits(f)); System.out.printf("%32s\n", sf); System.out.printf("%32s\n", sf.substring(9)); System.out.printf("%s\n", sd.substring(12)); System.out.printf("%s\n", sf.substring(9)); System.out.println(); double d = Math.sqrt(2); float f1 = (float)d; //System.out.println(d); //System.out.println(f1); sd = Long.toBinaryString(Double.doubleToLongBits(d)); System.out.printf("%64s\n", sd); System.out.printf("%64s\n", sd.substring(12)); sf = Integer.toBinaryString(Float.floatToIntBits(f1)); System.out.printf("%32s\n", sf); System.out.printf("%32s\n", sf.substring(9)); System.out.printf("%s\n", sd.substring(12)); System.out.printf("%s\n", sf.substring(9)); 打印结果 100000000001001001000011111101101010100010001000010110100011000 001001000011111101101010100010001000010110100011000 1000000010010010000111111011011 0010010000111111011011 001001000011111101101010100010001000010110100011000 0010010000111111011011 11111111110110101000001001111001100110011111110011101111001101 10101000001001111001100110011111110011101111001101 111111101101010000010011110011 101010000010011110011 10101000001001111001100110011111110011101111001101 101010000010011110011
------解决方案--------------------
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import javax.swing.*;
import javax.swing.Timer;
public class Tetris extends JFrame {
public Tetris() {
Tetrisblok a = new Tetrisblok();
addKeyListener(a);
add(a);
}
public static void main(String[] args) {
Tetris frame = new Tetris();
JMenuBar menu = new JMenuBar();
frame.setJMenuBar(menu);
JMenu game = new JMenu("游戏");
JMenuItem newgame = game.add("新游戏");
JMenuItem pause = game.add("暂停");
JMenuItem goon = game.add("继续");
JMenuItem exit = game.add("退出");
JMenu help = new JMenu("帮助");
JMenuItem about = help.add("关于");
menu.add(game);
menu.add(help);
frame.setLocationRelativeTo(null);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);