Today I worked on a small but very interesting problem in Java: reversing the words in a sentence. For example: Input: "I love Java" Output: "Java love I" Here’s a clean approach using split() Key Points: trim() removes leading and trailing spaces split("\\s+") handles multiple spaces between words This simple program is a great example of using Java’s string handling and array manipulation. Try it out and see how easy it is to reverse words in any sentence! #Java #Programming #Coding #DSA #ProblemSolving
Reversing words in a sentence with Java
More Relevant Posts
-
Day 7/30 — Java + DSA Journey 🚀 Today’s focus was on understanding and working with Strings in Java: ➡ Immutable vs Mutable Strings ➡ StringBuffer (synchronized, thread-safe) ➡ StringBuilder (fast, non-synchronized) ➡ Efficiency in text operations Strings are at the heart of Java programming. Knowing when to use String, StringBuffer, or StringBuilder is key to writing efficient and scalable code. Revising all week’s concepts has solidified the foundation Small steps, consistent progress 🌱 #Java #DSA #Strings #LearnInPublic #CodingJourney
To view or add a comment, sign in
-
🌟 Main Method in Java The main method is the entry point of every Java program. It allows the OS to hand over control to your code for execution. 📝 Signature: public static void main(String[] args) 💡 public → accessible to OS 💡 static → no object needed 💡 void → no return 💡 String[] args → command-line arguments ✅ Example: class Demo { public static void main(String[] args) { System.out.println("Hello World!"); } } #Java #ProgrammingBasics #Coding #HelloWorld #LearningJourney #ComputerScience
To view or add a comment, sign in
-
-
♻️ Garbage Collection in Java — Simplified! 🚀 In Java, memory management is handled automatically using a process called Garbage Collection (GC). It removes objects that are no longer in use, keeping your application memory-efficient and stable! 💡 🧠 How it works: obj1 and obj2 are made null, so they’re no longer referenced. System.gc() requests the JVM to perform Garbage Collection. Before destroying an object, the JVM automatically calls the finalize() method. Adding a small delay (Thread.sleep(1000)) helps give the JVM time to trigger GC before the program exits. ✅ Sample Output: Garbage collector called for object: GarbageCollector@6bc7c054 Garbage collector called for object: GarbageCollector@232204a1 Main method completed Java’s Garbage Collector ensures that memory is managed efficiently — so developers can focus on logic, not cleanup! 💪 #Java #GarbageCollection #Programming #JavaDeveloper #Coding #TechLearning
To view or add a comment, sign in
-
-
♻️ Garbage Collection in Java — Simplified! 🚀 In Java, memory management is handled automatically using a process called Garbage Collection (GC). It removes objects that are no longer in use, keeping your application memory-efficient and stable! 💡 🧠 How it works: obj1 and obj2 are made null, so they’re no longer referenced. System.gc() requests the JVM to perform Garbage Collection. Before destroying an object, the JVM automatically calls the finalize() method. Adding a small delay (Thread.sleep(1000)) helps give the JVM time to trigger GC before the program exits. ✅ Sample Output: Garbage collector called for object: GarbageCollector@6bc7c054 Garbage collector called for object: GarbageCollector@232204a1 Main method completed Java’s Garbage Collector ensures that memory is managed efficiently — so developers can focus on logic, not cleanup! 💪 #Java #GarbageCollection #Programming #JavaDeveloper #Coding #TechLearning
To view or add a comment, sign in
-
-
Day 18 of #50DaysOfCode – Java Today’s challenge: Calculate the Product of Digits in a Number! A simple yet logical problem that enhances understanding of loops and arithmetic operations 💡 📘 Example: Input → 234 Output → 24 (2 × 3 × 4 = 24) #Java #CodingChallenge #50DaysOfCode #CodeEveryday #LogicBuilding #LearnToCode #ProgrammingBasics
To view or add a comment, sign in
-
Day 20 of #50DaysOfCode – Java Today’s task: Find the sum of all odd digits in a given number! 🔢 A simple yet logical exercise that helps strengthen your understanding of loops, conditionals, and digit manipulation. 💡 👉 This program takes a number as input and calculates the total of its odd digits using a while loop and the modulus operator. #Java #CodingChallenge #50DaysOfCode #LearnToCode #ProgrammingBasics #LogicBuilding #CodeEveryday #JavaProgramming
To view or add a comment, sign in
-
Java Interfaces — Default vs Static Methods & Ambiguity Today I explored how Java handles multiple inheritance with interfaces, especially when both interfaces contain the same default method. ✅ Default methods are inherited ✅ Static methods belong to the interface — called using the interface name ⚠️ If two interfaces have the same default method, the implementing class must override it to avoid ambiguity. 🎯 Key Takeaways When two interfaces have the same default method, Java forces us to override & resolve the conflict We can call specific parent interface default methods using InterfaceName.super.method() Static methods in interfaces do not participate in inheritance → call like AAA.clear() 💬 What I learned today Java gives power with multiple interface inheritance, but also ensures clarity by requiring us to resolve ambiguity manually. Special thanks to my mentor Anand Kumar Buddarapu sir #Java #OOP #Interface #Programming #LearningJourney #CodeLife #SoftwareEngineering #JavaDeveloper #MultipleInheritance #TechLearning
To view or add a comment, sign in
-
💡 Today’s Java Practice: Understanding Shallow Copy in OOP I implemented a simple example using Character and Healthstatus classes to visualize how shallow copying affects object references in Java. When we copy one object into another using the same reference, any change made in one reflects in the other — that’s the core idea of shallow copy. 🧠 This concept helped me understand memory references and object cloning better! #Java #OOP #LearningJourney #CodingPractice #CoreJava
To view or add a comment, sign in
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
With out the array concept. We go for the double for loop.. It run the time complex O(n).