Day 16: Decision Making Or Conditional Statement A statement which helps a programmer in making decision whether to execute a block of code or not is known as Decision Making or Conditional Statement. Types of decision making statement 1.if statement 2.if-else statement 3.if-else ladder 4.switch statement 1.if statement: if is a decision making statement which helps a programmer to make a decision whether to execute a block of code or not. syntax: if(condition){ // statements } execution flow : statements inside if block gets execute when condition evaluate true. otherwise if block gets skip or ignored. 2.if-else Statement: if-else is a decision making statement which helps a programmer to make a decision whether to execute a block of code or not based on condition. else always associated with if. we can't add statement in between if and else block otherwise we get compile time error. syntax: if(condition){ // statements } else{ // statements } execution flow: if condition evaluate true then the statements associated with if block gets execute otherwise else block gets execute. #corejava #learning #java #post
Decision Making in Java: Conditional Statements Explained
More Relevant Posts
-
🚀 Day 41 / 100 | Spiral Matrix II -Intuition: -The goal is to generate an n × n matrix filled with numbers from 1 to n^2 in spiral order. -Start from the top row, move right, then move down the right column, then move left across the bottom row, and finally move up the left column. -After completing one layer, shrink the boundaries and repeat the process until the matrix is filled. -Approach: O(n²) -Initialize an empty n × n matrix. -Maintain four boundaries: top, bottom, left, and right. -Start filling numbers from 1 to n^2. -Fill the top row from left -> right and move the top boundary down. -Fill the right column from top -> bottom and move the right boundary left. -Fill the bottom row from right ->left and move the bottom boundary up. -Fill the left column from bottom -> top and move the left boundary right. -Repeat the process until all elements are filled. -Complexity: Time Complexity: O(n²) Space Complexity: O(n²) #100DaysOfCode #Java #DSA #LeetCode #Matrix
To view or add a comment, sign in
-
-
Solved the classic #linked_list problem https://lnkd.in/gWWFrt_g 👉 Add Two Numbers (LeetCode) Instead of converting the lists into integers, I handled the addition digit-by-digit just like manual addition using: A dummy node to simplify linked list construction ✔️ Carry handling logic ✔️ Clean pointer movement ✔️ O(n) Time Complexity ✔️ O(n) Space Complexity We traverse both linked lists simultaneously, calculate the sum at each node along with the carry, create a new node for the result, and move forward just like elementary school addition. Runtime: 1 ms Faster than 99.79% of Java submissions 1569 / 1569 test cases passed This problem reinforced something important: Strong fundamentals in data structures (especially Linked Lists) make complex-looking problems feel structured and logical. Building logic ! On to the next one ! #Java #LeetCode #DSA #LinkedList
To view or add a comment, sign in
-
-
𝑷𝒐𝒕𝒆𝒏𝒕𝒊𝒂𝒍 𝑩𝒖𝒈 𝑰𝒅𝒆𝒏𝒕𝒊𝒇𝒊𝒆𝒅 𝒊𝒏 𝑳𝒆𝒆𝒕𝑪𝒐𝒅𝒆 𝑬𝒙𝒆𝒄𝒖𝒕𝒊𝒐𝒏 𝑻𝒊𝒎𝒆 𝑪𝒂𝒍𝒄𝒖𝒍𝒂𝒕𝒊𝒐𝒏 I recently noticed an issue with how LeetCode calculates and displays code execution time. By adding a simple static block with a shutdown hook, it is possible to alter the displayed runtime of a submitted solution. This indicates that the execution time can be influenced outside the actual algorithm logic, which should ideally not be possible. Below is the code snippet that demonstrates this behavior: static { Runtime.getRuntime().addShutdownHook(new Thread(() -> { try (FileWriter writer = new FileWriter("display_runtime.txt")) { writer.write("0"); } catch (IOException e) { e.printStackTrace(); } })); } This suggests a bug on LeetCode’s end, where execution time tracking may be relying on artifacts that can be manipulated during JVM shutdown. Sharing this for awareness and hoping the LeetCode team can look into it to ensure fair and accurate performance measurement for all submissions. #LeetCode #Java #JVM #CompetitiveProgramming #SoftwareEngineering #Performance #Debugging LeetCode
To view or add a comment, sign in
-
Day 20-What I Learned In a Day(JAVA) What is Method? A method is a block of code that performs a specific task. It is used to improve code reusability, readability, and modularity. Syntax: accessModifierreturnTypemethodName(parameters) { // method body } Important Terminologies: 1️⃣ Method Signature Method name + parameter list only. Example: add(int, int) (It does NOT include return type.) 2️⃣ Method Declaration Return type + method name + parameters (without body). Example: public int add(int a, int b); 3️⃣ Method Definition Complete method including body (implementation). Example: public int add(int a, int b) { return a + b; } Practice Done Today ✔ Created methods for addition, subtraction, multiplication,Division ✔ Understood static and non-static methods ✔ Practiced method calling ✔ Practiced dynamic input using Scanner Practiced 👇 #Java #CoreJava #JavaMethods #MethodSignature #MethodDeclaration #MethodDefinition #StaticVsNonStatic #OOPSConcepts #JavaBasics #CodingPractice #LearningJourney
To view or add a comment, sign in
-
Bean Lifecycle in Spring : A Spring Bean lifecycle describes what happens to a bean from creation to destruction. 🔄 Bean Lifecycle – Step by Step: 1️⃣ Bean Creation ➡ Spring creates the object 2️⃣ Dependency Injection ➡ Required dependencies are injected 3️⃣ Initialization ➡ Bean is ready to use 4️⃣ Business Logic Execution ➡ Bean is used in the application 5️⃣ Bean Destruction ➡ Bean is destroyed when the application stops 🧠 How Spring Manages This? Spring’s IoC Container controls the entire lifecycle automatically. 📌 Common Lifecycle Hooks @PostConstruct → runs after bean creation @PreDestroy → runs before bean destruction @Component class MyBean { @PostConstruct public void init() { System.out.println("Bean Initialized"); } @PreDestroy public void destroy() { System.out.println("Bean Destroyed"); } } 💡 Simple Way to Remember Create → Inject → Initialize → Use → Destroy #Spring #SpringBoot #BeanLifecycle #Java #LearningInPublic #BackendDevelopment
To view or add a comment, sign in
-
-
Alright, let's talk Spring Dependency Injection. THE PAIN: Ever found yourself writing boilerplate code to manually create and wire up objects? Imagine a class needing several other components. Before DI, you'd be looking at new SomeService(new AnotherComponent(), new YetAnotherThing()) scattered everywhere. This makes code hard to read, test, and maintain. Dependencies become tangled. THE INSIGHT: Spring Dependency Injection (DI) tackles this head-on. Instead of a class creating its own dependencies, Spring gives them to the class. This is often called "Inversion of Control" (IoC). Decoupling: Classes don't need to know how* their dependencies are created or what their concrete types are. * Testability: You can easily swap out real dependencies for mock versions during testing. * Configuration: Dependency wiring is managed centrally, usually via annotations or configuration files. EXAMPLE: // Without DI (painful) class MyService { private OtherService otherService; public MyService() { this.otherService = new OtherService(); // Manual creation } // ... } // With Spring DI @Service public class MyService { private final OtherService otherService; // Dependency injected @Autowired // Spring finds and injects an instance of OtherService public MyService(OtherService otherService) { this.otherService = otherService; } // ... } @Service public class OtherService { // ... } IMPACT: Cleaner code, fewer bugs. Spring DI dramatically simplifies object management, making your applications more modular, robust, and a joy to work with. #Java #Spring #SoftwareEngineering
To view or add a comment, sign in
-
-
🚀 How a small refactor improved performance by 40% Problem: A service was timing out under load. What I changed: Replaced nested loops with HashMap lookups Reduced DB calls using batch fetching Added proper indexes Result: ✅ Faster response time ✅ Happier users ✅ Zero infra cost increase Lesson: Optimization is more about thinking than tools. #Java #PerformanceOptimization #BackendDeveloper #Microservices
To view or add a comment, sign in
-
📘 LeetCode Daily — Problem #3634 Worked through LeetCode 3634 today using the Sliding Window pattern. The interesting part wasn’t just arriving at the solution, but understanding why this approach fits and how implementation details matter. One key takeaway was recognizing when to switch from int to long to prevent overflow—something that’s easy to miss but critical for correctness. Problems like this reinforce that efficient logic and careful data handling go hand in hand. #LeetCode #SlidingWindow #DSA #Java #ProblemSolving #DailyPractice
To view or add a comment, sign in
-
-
🔥 Day 87 of #100DaysOfCode Today’s challenge: LeetCode: Implement Stack using Queues 📚🔁 📌 Problem Summary Implement a stack (LIFO) using only queue operations: push(x) pop() top() empty() You can only use standard queue operations (offer, poll, peek, isEmpty). 🧠 Approach: Two Queues Since stack is LIFO and queue is FIFO, we simulate stack behavior by rearranging elements during push. ⚙️ Strategy Used: Move all elements from q1 → q2 Add new element to q1 Move everything back from q2 → q1 Now: The newest element is always at the front of q1 pop() becomes simple → just q1.poll() 🔁 Key Idea Make push() costly Make pop() O(1) ⏱ Time Complexity push() → O(n) pop() → O(1) top() → O(1) empty() → O(1) 💾 Space Complexity: O(n) ⚡ Performance Runtime: 0 ms 100% faster than other submissions 🚀 💡 What I Learned Data structures can simulate each other. The trick is choosing where to handle the complexity. Understanding internal behavior matters more than memorizing code. Stack → Queue → Simulation mastery growing stronger 💪 On to Day 88 🔥 #100DaysOfCode #LeetCode #Stack #Queue #Java #DSA #InterviewPrep
To view or add a comment, sign in
-
-
Day 30 - Largest Number Technique Used: Custom Comparator Sorting Key Idea: Converted integers to strings and sorted them using a custom comparator: Order decided by comparing (b + a) vs (a + b) This ensures the concatenation forms the largest possible number. Handled edge case where all values are 0. Time: O(n log n) #Day30 #LeetCode #Java #Sorting #Comparator #DSA #Algorithms
To view or add a comment, sign in
-
Explore related topics
Explore content categories
- Career
- Productivity
- Finance
- Soft Skills & Emotional Intelligence
- Project Management
- Education
- Technology
- Leadership
- Ecommerce
- User Experience
- Recruitment & HR
- Customer Experience
- Real Estate
- Marketing
- Sales
- Retail & Merchandising
- Science
- Supply Chain Management
- Future Of Work
- Consulting
- Writing
- Economics
- Artificial Intelligence
- Employee Experience
- Workplace Trends
- Fundraising
- Networking
- Corporate Social Responsibility
- Negotiation
- Communication
- Engineering
- Hospitality & Tourism
- Business Strategy
- Change Management
- Organizational Culture
- Design
- Innovation
- Event Planning
- Training & Development