Thursday, 24 April 2025

Math.random() in Java

 

Get Whole Numbers

You can use it to get random integers too:

int num = (int)(Math.random() * 10); // 0 to 9


Mini Challenge: Dice Game

Write a program that:

  • Rolls two dice

  • Adds them together

  • Prints “You rolled: X + Y = Z”

No comments:

Post a Comment

👨‍💻 How I Started Learning Java at 15 (and You Can Too)

  When I first heard of Java, I thought it was just something to do with Minecraft mods or Android apps. I didn’t realize it would become my...