Learned Control Statements in Java (if, else, switch)

🔥 Day 6 – Control Statements in Java (if, else, switch) 🧠 Post Content (for LinkedIn): ☕ Day 6 of my 30-day Core Java journey! Today, I learned about Control Statements — the part of Java that helps programs make decisions and execute code conditionally. These statements control the flow of execution based on conditions — just like how we make decisions in real life! 💡 Types of Control Statements 🔹 1. if Statement Executes a block of code only if a condition is true. int age = 18; if (age >= 18) {   System.out.println("Eligible to vote"); } 🔹 2. if-else Statement Chooses between two paths. int marks = 45; if (marks >= 50) {   System.out.println("Pass"); } else {   System.out.println("Fail"); } 🔹 3. if-else-if Ladder Tests multiple conditions. int score = 80; if (score >= 90) System.out.println("A Grade"); else if (score >= 75) System.out.println("B Grade"); else System.out.println("C Grade"); 🔹 4. switch Statement Used when multiple outcomes depend on one variable. int day = 3; switch (day) {   case 1: System.out.println("Monday"); break;   case 2: System.out.println("Tuesday"); break;   case 3: System.out.println("Wednesday"); break;   default: System.out.println("Invalid day"); } 🎯 Takeaway: Control statements help you guide program logic — deciding what to do and when. They’re the heart of decision-making in Java 💪 #CoreJava #JavaLearning #PasupathiLearnsJava #JavaControlStatements #ProgrammingBasics

  • graphical user interface, application

To view or add a comment, sign in

Explore content categories