Allaka Yamuna lakshmi’s Post

Day 9/100 — Math Class & Type Casting in Java 🔢 Today I learned an interesting concept while working with numbers in Java. When we cast a decimal value to an integer, Java does not round the number—it simply truncates the decimal part. Example: (int) 9.99 = 9 ❗ (Not 10) If we actually want rounding, we should use the Math class: Math.round(9.99) → 10 This is an important detail because many beginners assume casting will round values, but it doesn’t. Understanding this helps avoid logical errors in programs. 💻 Challenge I tried today: Simulate 10 dice rolls using Java’s Math class and random number logic. Example approach: for (int i = 1; i <= 10; i++) { int dice = (int)(Math.random() * 6) + 1; System.out.println("Roll " + i + ": " + dice); } Learning small but powerful concepts every day and building strong Java fundamentals step by step 🚀 #Java #CoreJava #MathClass #TypeCasting #Programming #JavaLearning #100DaysOfCode

  • graphical user interface, text

To view or add a comment, sign in

Explore content categories