⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 main.java

📁 java的经典例子
💻 JAVA
字号:
import java.util.Random;

// Subclass that also has sequence generators for byte and short.
class NRandom extends Random {
    NRandom() {
    }

    NRandom(long seed) {
        super(seed);
    }

    public byte nextByte() {
        return (byte)next(8);   // Random low-order 8 bits
    }

    public short nextShort() {  // Random low-order 16 bits
        return (short)next(16);
    }
}

class Main {
    public static void main(String[] args) {
        NRandom rand = new NRandom(1997);

        // Let's see what the byte sequence looks like.
        for (int i = 0; i < 20; i++) {
            System.out.print(rand.nextByte() + " ");
        }
        System.out.println("\n");

        // Reset seed and try the short sequence.
        rand.setSeed(1997);
        for (int i = 0; i < 20; i++) {
            System.out.print(rand.nextShort() + " ");
        }
        System.out.println("\n");
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -