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

🚀 Top 3 Java Projects Every Beginner Should Build (With Code Ideas)

 Tired of just printing "Hello World"? It’s time to build something real. 💻 If you're learning Java and want to stand out, ...