Đang chuẩn bị liên kết để tải về tài liệu:
Java Programming for absolute beginner- P5

Đang chuẩn bị nút TẢI XUỐNG, xin hãy chờ

Java Programming for absolute beginner- P5:Hello and welcome to Java Programming for the Absolute Beginner. You probably already have a good understanding of how to use your computer. These days it’s hard to find someone who doesn’t, given the importance of computers in today’s world. Learning to control your computer intimately is what will separate you from the pack! By reading this book, you learn how to accomplish just that through the magic of programming. | JavaProgAbsBeg-03.qxd 2 25 03 8 49 AM Page 58 FIGURE 3.2 The NumberMaker displays random numbers generated by the Math.random method. The java.util.Random Class Another way that you can generate random numbers is by using the Random class in the java.util package. The Random class offers different methods for different data types. Specifically it can generate random booleans doubles floats i nts and longs. Refer to Table 3.1 for a list of these methods. Table 3.1 Some java.util.Random Methods 4 Method Description boolean nextBoolean Randomly returns either true or false boolean values. double nextDouble Returns a random double value ranging from 0.0 inclusive to 1.0 exclusive . float nextFloat Returns a random float value ranging from 0.0 inclusive to 1.0 exclusive . int nextInt Returns a random int value all 232 values are possible . int nextInt int n Returns a random int value ranging from 0 inclusive to n exclusive . long nextLong Returns a random long value all 264 values are possible . X J In order to call one of the methods in Table 3.1 you need to create a new Random object first and then use that object to call the desired method. The NumberMakerUtil application demonstrates how this is done. Take a look at the source code NumberMakerUtil Uses java.util.Random to generate random numbers team Line - live informative Non-cost and Genuine Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark. JavaProgAbsBeg-03.qxd 2 25 03 8 49 AM Page 59 import java.util.Random public class NumberMakerUtil public static void main String args Random rand new Random System.out.println Random Integers System.out.println rand.nextInt rand.nextInt rand.nextInt int iLimit 11 System.out.println nRandom Integers between 0 and 10 System.out.println rand.nextInt iLimit rand.nextInt iLimit rand.nextInt iLimit System.out.println nRandom Floats System.out.println rand.nextFloat rand.nextFloat rand.nextFloat System.out.println nRandom Booleans System.out.println .

Đã phát hiện trình chặn quảng cáo AdBlock
Trang web này phụ thuộc vào doanh thu từ số lần hiển thị quảng cáo để tồn tại. Vui lòng tắt trình chặn quảng cáo của bạn hoặc tạm dừng tính năng chặn quảng cáo cho trang web này.