Why every time I run this code, the same result?

System.out.print((int)Math.random()*40+1); 

Always displays 1 - why?

    1 answer 1

    Because you cast to int a number that is less than one.

     (int)Math.random()*40 Эта штука у тебя всегда ноль =) 

    What you need looks like this

      System.out.print((int)(Math.random()*40+1)); 
    • Exactly! Thank!! - qwas13
    • It happens .. just need to sleep more) - Stas0n