簡體   English   中英

如何對int隨機數和雙隨機數求和?

[英]How to sum int random number and double random number?

這是代碼:

    Random randomNumber = new Random();
    System.out.println(randomNumber.nextInt(10));
    Random randomNumberTwo = new Random();
    System.out.println(randomNumberTwo.nextDouble());
    System.out.println(randomNumber + randomNumberTwo);

終端說:java:二元運算符'+'的錯誤操作數類型

randomNumber 和 randomNumberTwo 是生成器,因此為了添加它們,您需要從中生成下一個值:

Random randomNumber = new Random();
Random randomNumberTwo = new Random();
System.out.println(randomNumber.nextInt(10) + randomNumberTwo.nextDouble());

在這里,您將類隨機數的對象添加到此

  Random randomNumber = new Random();
   int a = randomNumber.nextInt(10)
    System.out.println(randomNumber.nextInt(10));
    Random randomNumberTwo = new Random();
    double b = randomNumberTwo.nextDouble()
    System.out.println(randomNumberTwo.nextDouble());
    System.out.println(a + b);

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM