Day(15/30) Today I practiced a simple yet logical Java problem: Find the largest word in a sentence. Here’s the logic in simple steps 1 Split the sentence into words using split(" ") 2 Loop through each word using index-based for loop 3 Compare each word’s length 4 Keep updating the longest word String sentence = "Java is a powerful programming language"; String[] words = sentence.split(" "); String largestWord = ""; int maxLength = 0; for (int i = 0; i < words.length; i++) { String word = words[i]; if (word.length() > maxLength) { maxLength = word.length(); largestWord = word; } } System.out.println("Largest Word: " + largestWord); This small exercise helped me understand string traversal and comparison in Java better. Sometimes, even simple problems teach powerful concepts like loops, arrays, and string handling. #Java #Programming #BCA #LearningInPublic #90DaysOfCode #CodingJourney
Finding the largest word in a sentence with Java
More Relevant Posts
-
Reverse of a number : To reverse a given number in Java, use a loop to extract digits from the number one by one and build the reversed number. Here’s a clear Java program using a while loop, commonly recommended for beginners. import java.util.Scanner; public class ReverseNumber { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); System.out.print("Enter a number to reverse: "); int number = scanner.nextInt(); int reverse = 0; while (number != 0) { int digit = number % 10; // Get last digit reverse = reverse * 10 + digit; // Shift and add number /= 10; // Remove last digit } System.out.println("Reversed Number: " + reverse); } } Explanation: The loop extracts the last digit using number % 10.It multiplies the reversed number by 10 and adds the extracted digit.The original number is divided by 10 in each iteration to remove the last digit. #JavaProgramming #LearnJava #JavaBasics #CodingChallenge #ProgrammingTips #CodeNewbie #DeveloperLife #100DaysOfCode #JavaDeveloper #SoftwareDevelopment #CodingPractice #TechLearning #ProgrammingCommunity
To view or add a comment, sign in
-
Today I’m sharing one of the most important Java concepts — Deep Copy vs Shallow Copy. When we copy objects in Java, it’s not always about duplicating data — sometimes we only copy references. This can cause unexpected behavior when one object changes and the other gets affected too. That’s where Deep Copy comes in! 💡 It creates a completely new object with its own copy of the data — ensuring changes in one object don’t impact the other. Here’s a simple example using HealthStatus and Character classes to show how Deep Copy keeps objects independent 👇 ✅ Output: The original object remains unchanged even after modifying the copy — a true Deep Copy! 💭 Deep Copy ensures data independence and prevents accidental side effects when working with objects containing references. #Java #Programming #OOP #DeepCopy #ShallowCopy #LearningJourney #CodeWithPavan #SoftwareDevelopment
To view or add a comment, sign in
-
🚀 *Learning Update: Java Arrays & Strings* This week, I explored *Arrays* and *Strings* in Java! 🌟 ✅ *Arrays*: Learned how to store multiple values of the same type in a single data structure, access elements using indices, iterate using loops, and perform common operations like sorting, searching, and updating values. ✅ *Strings*: Practiced handling text data, using methods like `length()`, `charAt()`, `substring()`, `concat()`, `replace()`, and `split()`. I also explored string immutability and how to manipulate strings efficiently. #Java #Programming #Coding #LearningJourney #Arrays #Strings #SoftwareDevelopment
To view or add a comment, sign in
-
-
My journey of Java coding begins now Today I wrote the first java program import java.util.*; public class addtwonumbers(){ public static void main(String [] ARGS){ System.out.println( "Enter two numbers"); Scanner sc = new Scanner (System.in); int a = sc.nextInt(); int b = sc.nextInt(); int sum = a+b; System.out.println("Sum of two numbers"+sum) sc.close(); } explanation: util is a package for using scanner class we are creating scanner named sc. system.in => means we are taking input from the user This line asks the user to enter the first number. Then sc.nextInt() listens and saves that number into a box named a Again, Java listens for the next number and stores it in another sticky note labeled b Java now prints the final answer on the screen. Analogy: It’s like the cashier announcing your total amount Open for any suggestions #Java #Coding #DailyLearning #AWS #LinkedIn #Python #Selenium #AutomationTesting #Restapi #Programming
To view or add a comment, sign in
-
🚀 Java Learning – I once wondered: 👉 “Why can’t we modify a String like we do with a StringBuilder?” Here’s why Strings are immutable in Java 👇 1️⃣ Security – Strings store sensitive data like DB URLs, usernames, and passwords. If they were mutable, their values could be changed after creation. 2️⃣ String Pool Optimization – The JVM reuses immutable Strings to save memory and improve performance. 3️⃣ Thread Safety – Immutable Strings can be shared safely across multiple threads. 4️⃣ HashMap Reliability – The hashCode of a String stays constant, making it a reliable key in Maps. ✨ Takeaway: Immutability is one of the key reasons Java is secure, efficient, and consistent. #Java #JavaDeveloper #Coding #TechLearning #StringImmutability #SoftwareDevelopment #Programming #CleanCode #JavaTips
To view or add a comment, sign in
-
🚀 Day 2/100 — Understanding Java Syntax, Variables & Data Types 🧩 Continuing my #100DaysOfJavaChallenge, today was all about learning the building blocks of Java programming — how data is stored, accessed, and manipulated in a program. ☕💻 💡 What I learned today ✅ Basic structure of a Java program ✅ Declaring and using variables ✅ Different data types in Java (int, float, char, boolean, String, etc.) ✅ How type casting works (implicit & explicit conversion) ✅ Using variables inside System.out.println() 💻 Sample Practice Code public class Day2 { public static void main(String[] args) { int age = 20; double height = 5.6; char grade = 'A'; boolean isLearning = true; String name = "Raunit"; System.out.println("Name: " + name); System.out.println("Age: " + age); System.out.println("Height: " + height); System.out.println("Grade: " + grade); System.out.println("Learning Java: " + isLearning); } } #Day2 #100DaysOfCode #JavaDeveloper #LearningJourney #SpringBoot #SQL #JDBC #CodingChallenge #JavaProgramming #IntelliJIDEA #ProgrammerLife #Variables #DataTypes
To view or add a comment, sign in
-
🚀 Day 4 of My DSA with Java Journey 📘 Problem: Square of a Sorted Array 🧩 Topic: Two Pointers 💻 Language: Java ⚙️ Approach: Two Pointer Technique (O(n)) 🔍 What I Learned: Handling both negative and positive numbers while keeping the array sorted after squaring — optimized using two pointers instead of sorting after squaring. ✨ Key Takeaway: Think in terms of pointers and comparisons, not just brute force — that’s how optimization begins. #Java #DSA #LeetCode #TwoPointers #CodingJourney #100DaysOfCode #PlacementPrep #LearnInPublic #CodingCommunity #JavaDeveloper
To view or add a comment, sign in
-
-
Day 9 of my #JavaWithDSAChallenge Today’s topic: Java Exception Handling Problem: Given two integers a and b, find the minimum value of a $ b where $ can be any arithmetic operation (+, -, *, /). We also need to handle division by zero using Exception Handling in Java. Key Concepts: try-catch block to handle runtime errors gracefully Arithmetic operations and Math.min() for comparisons Handling invalid division cases safely Code Snippet: class Solution { public int findMin(int a, int b) { int add = a + b; int sub = a - b; int mul = a * b; int div = Integer.MAX_VALUE; try { div = a / b; } catch (ArithmeticException e) { // Division by zero handled } int min1 = Math.min(add, sub); int min2 = Math.min(mul, div); return Math.min(min1, min2); } } Example: Input: a = 5, b = -5 Output: -25 Explanation: Among (0, 10, -25, -1), the minimum is -25. Learning: Exception Handling is not just about catching errors - it’s about writing safe and reliable code that doesn’t break in unexpected situations. #Java #CodingChallenge #DSA #LearningInPublic #100DaysOfCode #WomenInTech #JavaDeveloper
To view or add a comment, sign in
-
-
💡 Today I learned about Prime Factorization in Java! Prime Factorization means breaking a number into its prime factors — the building blocks of the number. 🧩 Basic Approach: int i = 2; while (n > 1) { while (n % i == 0) { System.out.println(i); n = n / i; } i++; } ⏱️ Time Complexity: O(n) ⚙️ Optimized Approach: int i = 2; while (i * i <= n) { while (n % i == 0) { System.out.println(i); n = n / i; } i++; } if (n > 1) System.out.println(n); ⏱️ Time Complexity: O(√n) ✅ Key Takeaway: Checking factors only up to √n makes the algorithm much faster — no need to go till n. Small change, big improvement in performance! #Java #DSA #LearningJourney #Coding #Algorithms #Optimization
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